1 REAL FUNCTION ran1(idum)
2 INTEGER idum,IA,IM,IQ,IR,NTAB,NDIV
4 PARAMETER (IA=16807,IM=2147483647,AM=1./IM,IQ=127773,IR=2836,
5 * NTAB=32,NDIV=1+(IM-1)/NTAB,EPS=1.2e-7,RNMX=1.-EPS)
6 C "Minimal" random number generator of Park and Miller with Bays-Durham shuffle and
7 C added safeguards. Returns a uniform random deviate between 0.0 and 1.0 (exclusive of
8 C the endpoint values). Call with idum a negative integer to initialize; thereafter, do not
9 C alter idum between successive deviates in a sequence. RNMX should approximate the largest
10 C floating value that is less than 1. Recommended for seqences smaller than 100e6 (i.e. 5%
12 C (from Press etal, Numerical Recipes in Fortran 77)
13 CcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccC
14 INTEGER j,k,iv(NTAB),iy
16 DATA iv /NTAB*0/, iy /0/
17 if (idum.le.0.or.iy.eq.0) then ! initialize
18 idum=max(-idum,1) ! load the shuffle table (after 8 warmups)
21 idum=IA*(idum-k*IQ)-IR*k
22 if (idum.lt.0) idum=idum+IM
23 if (j.le.NTAB) iv(j)=idum
27 k=idum/IQ ! start here when not initializing
28 idum=IA*(idum-k*IQ)-IR*k
29 if (idum.lt.0) idum=idum+IM