c estPi.f c c Program to estimate Pi using random number generation. c c Bruce M. Bolden c October 14, 1997 c ------------------------------------------------------- program EstPi c integer nHits integer nTries parameter( nTries = 50 ) c integer seed real x, y c nHits = 0 c seed = 12357 c seed = 987653 ! negative values! do i = 1, nTries call RANDOM(seed, x) call RANDOM(seed, y) !write(6,*) x if( IsInside(x,y) ) then nHits = nHits + 1 endif end do c pi = 4.0 * real(nHits)/real(nTries) write( 6, * ) 'Pi: ', pi c stop end c IsInside c c Test if (x,y) lies inside the unit circle c logical function IsInside( x, y ) real x, y c if( x*x + y*y .LE. 1.0 ) then IsInside = .TRUE. else IsInside = .FALSE. endif c return end c RANDOM c c Random number generation subroutine c subroutine RANDOM( iSEED, rand ) integer iSEED real rand c iSEED = 2045*iSEED + 1 iSEED = iSEED - (iSEED/1048576) * 1048576 rand = real(iSEED+1) / 1048576.0 c return end