The most common algorithms for generating pseudorandom numbers are based on the linear congruential random number generator invented by Lehmer. Given a positive integer m called the modulus and an initial seed value
where a and c are carefully chosen integers such that
For example, the parameters a=13, c=1, m=16 and
The first m elements of this sequence are distinct and appear to have been drawn at random from the set
Notice that the elements of the sequence alternate between odd and even integers. This follows directly from Equation
The least significant two bits are cyclic with period four and the least significant three bits are cycle with period eight! (These patterns arise because m=16 is also a multiple of 4 and 8). The existence of such patterns make the sequence less random. This suggests that the best choice for the modulus m is a prime number.
Not all parameter values result in a period of m. For example, changing the multiplier a to 11 produces the sequence
the period of which is only m/2. In general because each subsequent element of the sequence is determined solely from its predecessor and because there are m possible values, the longest possible period is m. Such a generator is called a full period generator.
In practice the increment c is often set to zero. In this case, Equation
This is called a multiplicative linear congruential random number generator. (For
In order to prevent the sequence generated by Equation
Notice that the first 12 elements of the sequence are distinct. Since a multiplicative congruential generator can never produce a zero, the maximum possible period is m-1. Therefore, this is a full period generator.
As the final step of the process, the elements of the sequence are normalized by division by the modulus:
In so doing, we obtain a sequence of random numbers that fall between zero and one. Specifically, a mixed congruential generator (