Home Lehmer

Lehmer's method is a type of "Prime Modulus Multiplicative Linear Congruential Generator" which operates in a multiplicative group of integers modulo m. The genious of Lehmer's algorithm is that if the multiplier a and prime modulus m are properly chosen, the resulting sequence {xn} will be statistically indistinguishable from a sequence drawn at random from the set {1,2,...,m1}.


The recursive formula applied in the method is:


xn+1=axnmodm.

There are many ways of choosing the numbers a, m and the seed x0. Different values would cause the method to reach its period faster when such numbers are not "good enough".

Let's take an example: a=6, m=13 and x0=1; The resulting sequence is {1,6,10,8,9,2,12,7,3,5,4,11,1,...}, which has a period of 12.


Choosing a,m and x0

In general we want our choice of m to be the highest possible prime number, this comes, however, at a big computing cost. For this reason, it's very common to work with numbers m that are a power of 2. Doing so guarantees us that the period would be at most m/4, which is pretty low, but this period would be even smaller when m is even. Due to this, a good option for m is, for example m=2311=2147483647.


The best choice for x0 is to make it coprime with m, this becomes a trivial task when m is prime and a bit more complicaten when it is not. Lehmer suggested a=75=16807 and m=2311, which is a Mersenne prime number and 0<x0<2311. This choice of a generates a full period function, which means it'll have a period of m1


Drawing the sequence

You can now choose different values for a, m and x0 and the drawing will paint each pixel black or white depending on weather the random number generated is smaller or greater than 0.5. A bad choice of a, m and x0 will result in an image with a recognizable pattern.

Suggested values: a= 16807, m= 2147483647 x0= 14