About the Linear Congruential Generator
History
The Lehmer Generator attracted significant attention due to its simple design and general effectiveness. In 1958, it was elaborated upon by W. E. Thomson and A. Rotenberg, who added a new variable to Lehmer's equation. This new variable, called c, is used to increment the Seed value each time the generator is called, resulting in much longer periods.
Some developers have also added bit shifting and masking to their implementations, which helps scramble the random numbers their PRNGs generate.
Some developers have also added bit shifting and masking to their implementations, which helps scramble the random numbers their PRNGs generate.
Concept
The formula for this generator is X1 = (aX0 + c) mod M.
While the values for a, M and c are generally chosen by the person implementing the Pseudo-Random Number Generator, better results are obtained if a is a primitive root of M.
Note that if c is 0, then the PRNG is better categorized as a Lehmer PRNG.
While the values for a, M and c are generally chosen by the person implementing the Pseudo-Random Number Generator, better results are obtained if a is a primitive root of M.
Note that if c is 0, then the PRNG is better categorized as a Lehmer PRNG.
Tested Variants
- GNU C Library's rand
The GNU C standard library (GLIBC) offers an LCG variant in its standard library. - Java.util.random
The Java programming language offers a 48-bit LCG via the Java.util.random class. - Open Watcom's rand
Open Watcom likewise offers an LCG, though this one is limited to 15 bits.