real function RANDOM (seed) c Author: Glen Cowan c Date: 3-OCT-1997 c Multiplicative linear congruential random number generator. c The value RANDOM is uniformly distributed in [0,1]. c The first value of the input variable seed can be any large (32 bit) c integer. The next call to RANDOM should use the last ouput value of c seed. Modulus and multiplier values according to P.L. L'Ecuyer, c Comm. ACM 31 (1988) 742. See also S. Brandt, "Datenanalyse", c BI-Wissenschaftsverlag, Mannheim (1992), p. 76. c NOTE: This routine is for mainly for pedagogical purposes and simple c applications. For more sophisticated algorithms see e.g. the c CERN program library (routines RANMAR, RANLUX) and reviews such as c F. James, "A review of pseudorandom number generators", c Comp. Phys. Comm. 60 (1990) 329. implicit NONE integer a parameter (a = 40692) ! the multiplier integer m parameter (m = 2147483399) ! the modulus integer q parameter (q = m/a) integer k integer r integer seed c The algorithm below implements seed = MOD(a*seed,m) without producing c integer values outside [-m,m] (which would give overflow errors). r = MOD(m,a) k = seed/q seed = a*(seed - k*q) - k*r if (seed .lt. 0) seed = seed + m random = FLOAT(seed) / FLOAT(m) return END