Repeated calls to ran generate a sequence of random numbers with a uniform distribution.
r = ran( i ) | |||
---|---|---|---|
i |
INTEGER*4 |
Input |
Variable or array element |
r |
REAL |
Output |
Variable or array element |
See lcrans(3m).
demo% cat ran1.f * ran1.f -- Generate random numbers. INTEGER*4 i, n real r(10) i = 760013 do n = 1, 10 r(n) = ran ( i ) end do write ( *, "( 5 f11.6 )" ) r end demo% f77 -silent ran1.f demo% a.out 0.222058 0.299851 0.390777 0.607055 0.653188 0.060174 0.149466 0.444353 0.002982 0.976519 demo%
Note the following:
The range includes 0.0 and excludes 1.0.
The algorithm is a multiplicative, congruential type, general random number generator.
In general, the value of i is set once during execution of the calling program.
The initial value of i should be a large odd integer.
Each call to RAN gets the next random number in the sequence.
To get a different sequence of random numbers each time you run the program, you must set the argument to a different initial value for each run.
The argument is used by RAN to store a value for the calculation of the next random number according to the following algorithm:
SEED = 6909 * SEED + 1 (MOD 2**32)
SEED contains a 32-bit number, and the high-order 24 bits are converted to floating point, and that value is returned.