Lehmer's method is a type of "Prime Modulus Multiplicative Linear Congruential Generator"
which operates in a multiplicative group of integers modulo . The genious of Lehmer's
algorithm is that if the multiplier and prime modulus are properly chosen, the
resulting sequence will be
statistically indistinguishable from a sequence drawn at random
from the set .
The recursive formula applied in the method is:
There are many ways of choosing the numbers , and the seed . Different values
would cause the method to reach its period faster when such
numbers are not "good enough".
Let's take an example: , and ; The resulting sequence is , which has a period of .
Choosing and
In general we want our choice of 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
that are a power of . Doing so guarantees us that the period would be
at most , which is pretty low, but this period would be even
smaller when is even. Due to this, a good option for is, for example .
The best choice for is to make it coprime with , this becomes a trivial task when
is prime and a bit more complicaten when it is not. Lehmer suggested and
, which is a Mersenne prime number and . This choice of
generates a full period function, which means it'll have a period of
Drawing the sequence
You can now choose different values for , and and the drawing will paint each
pixel black or white depending on weather the random number generated is smaller or greater
than . A bad choice of , and will result in an image with a recognizable
pattern.