Environmental Engineering Reference
In-Depth Information
cong16807=rmod*DMax
Iseed=Rmod
RETURN
END
PROGRAM 2: A GOOD ROUTINE FOR GENERATING A TABLEOF
RANDOM NUMBERS IN MONTE CARLO SIMULATION.
***************************************************************
This program uses the R250/R521 combined generator described in:
A. Heuer, B. Duenweg and A.M. Ferrenberg, Comp. Phys. Comm. 103, 1
1997). It generates a vector, RanVec, of length RanSize 31-bit random
integers. Multiply by RMaxI to get normalized random numbers. You
will need to test whether RanCnt will exceed RanSize. If so, call
GenRan again to generate a new block of RanSize numbers. Always
remember to increment RanCnt when you use a number from the table.
***************************************************************
IMPLICIT non-E
INTEGER RanSize,Seed,I,RanCnt,RanMax
PARAMETER(RanSize = 10000)
PARAMETER(RanMax = 2147483647)
INTEGER RanVec(RanSize),Z1(250+RanSize),Z2(521+RanSize)
REAL*8 RMaxI
PARAMETER (RMaxI = 1.0D0/(1.0D0*RanMax))
COMMON/MyRan/RanVec,Z1,Z2,RanCnt
SAVE
Seed = 432987111
*****************************************
Initialize the random number generator.
*****************************************
CALL InitRan(Seed)*
***************************************************************
If the 10 numbers we need pushes us past the end of the RanVec vector,
call GenRan. Since we just called InitRan, RanCnt = RanSize we must
call it here.
***************************************************************
IF ((RanCnt + 10).GT. RanSize) THEN
Generate RanSize numbers and reset the RanCnt counter to 1
Call GenRan
END IF
Do I = 1,10
WRITE(*,*) RanVec(RanCnt + I-1),RMaxI*RanVec(RanCnt + I-1)
End Do
Search WWH ::




Custom Search