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