Re: Monte Carlo computation of PI with license numbers



On Tue, 3 Mar 2009 22:27:21 +0000 (GMT), nmm1@xxxxxxxxx wrote:

Does anybody here know anything?

Well, Sergeant, specifically of course we can know nothing -
unqualified - but like the rest of us, I've fenced my life
with a scaffolding of more or less speculative hypotheses.

Are you saying that we live in adobe huts of own bull***?

The answers to your previous questions are "yes" and "yes" :-)

The convergence is O(sqrt(N)), and it won't work because your
fractions are only 3 digits - i.e. are not uniformly distributed
between 0 and 1. I could work out what it will converge to, but
I can't be bothered.

Is this showing O(sqrt(N)) convergence?

E:\gfortran\dan>gfortran bres11.f90 -Wall -o out

E:\gfortran\dan>out
counter is 78572180
trials is 100000000
ratio is 0.78572180000000003
pi fourths is 0.78539816339744828

E:\gfortran\dan>type bres11.f90
implicit none
INTEGER,PARAMETER::dp=SELECTED_REAL_KIND(15)
integer :: i, digit, power, sum2, j, k
integer :: trials, counter
real(kind=dp) :: u, sum1, madereal, bias, temp, ratio
real(kind=dp) :: pair(2), pair_squared, pi_fourths

call init_seed()
pi_fourths = atan(1.0_dp)
power = 2
sum1 = 0.0
trials = 100000000
counter = 0

! main control
do i = 1, trials
do k =1,2
sum2 = 0
do j = 1, power
call random_number(u)
digit = 10 * u
sum2 = sum2 + digit * 10**(j-1)
end do
madereal = sum2 * 10.0_dp**(-1 * power)
bias = 10.0_dp**(-1*power)/2.0_dp
temp = madereal + bias
pair(k) = temp
end do !k
pair_squared = (pair(1)**2)+(pair(2)**2)
! count them up
if (pair_squared .lt. 1.0_dp) then
counter = counter + 1
endif
end do ! i

ratio = real(counter)/real(trials)

! output

print *, "counter is ", counter
print *, "trials is ", trials
print *, "ratio is ", ratio
print *, "pi fourths is ", pi_fourths

contains
subroutine init_seed()
integer :: n, ival(8), v(3), i
integer, allocatable :: seed(:)
call date_and_time(values=ival)
v(1) = ival(8) + 2048*ival(7)
v(2) = ival(6) + 64*ival(5) ! value(4) isn't really 'random'
v(3) = ival(3) + 32*ival(2) + 32*8*ival(1)
call random_seed(size=n)
allocate(seed(n))
call random_seed() ! Give the seed an implementation-dependent kick
call random_seed(get=seed)
do i=1, n
seed(i) = seed(i) + v(mod(i-1, 3) + 1)
enddo
call random_seed(put=seed)
deallocate(seed)
end subroutine

endprogram
! gfortran bres11.f90 -Wall -o out
E:\gfortran\dan>
--
larry gates

Anyway, my money is still on use strict vars . . .
-- Larry Wall in <199710011704.KAA21395@xxxxxxxx>
.