3 * Author: Terrence W. Holm Nov. 1988
6 * A prime modulus multiplicative linear congruential
7 * generator (PMMLCG), or "Lehmer generator".
8 * Implementation directly derived from the article:
10 * S. K. Park and K. W. Miller
11 * Random Number Generators: Good Ones are Hard to Find
12 * CACM vol 31, #10. Oct. 1988. pp 1192-1201.
15 * Using the following multiplier and modulus, we obtain a
18 * 1) Has a full period: 1 to 2^31 - 2.
19 * 2) Is testably "random" (see the article).
20 * 3) Has a known implementation by E. L. Schrage.
25 _PROTOTYPE( long seed
, (long lseed
));
26 _PROTOTYPE( long lrand
, (void));
28 #define A 16807L /* A "good" multiplier */
29 #define M 2147483647L /* Modulus: 2^31 - 1 */
30 #define Q 127773L /* M / A */
31 #define R 2836L /* M % A */
33 PRIVATE
long _lseed
= 1L;
38 long previous_seed
= _lseed
;
42 return(previous_seed
);
48 _lseed
= A
* (_lseed
% Q
) - R
* (_lseed
/ Q
);
50 if (_lseed
< 0) _lseed
+= M
;