A Linear Congruential Generator (LCG) represents one of the oldest and bestknown pseudorandom number generator algorithms.^{[1]} The theory behind them is easy to understand, and they are easily implemented and fast.
The generator is defined by the recurrence relation:
where X_{n} is the sequence of pseudorandom values, and
are integer constants that specify the generator.
Contents
Period length
The period of a general LCG is at most m, and for some choices of a much less than that. Provided that c is nonzero, the LCG will have a full period for all seed values if and only if:^{[2]}
While LCGs are capable of producing decent pseudorandom numbers, this is extremely sensitive to the choice of the parameters c, m, and a.
Historically, poor choices had led to ineffective implementations of LCGs. A particularly illustrative example of this is RANDU which was widely used in the early 1970s and lead to many results which are currently being questioned because of the use of this poor LCG.^{[3]}
Parameters in common use
The most efficient LCGs have an m equal to a power of 2, most often m = 2^{32} or m = 2^{64}, because this allows the modulus operation to be computed by merely truncating all but the rightmost 32 or 64 bits. The following table lists the parameters of LCGs in common use, including builtin rand() functions in runtime libraries of various compilers.
^{[citation needed]}
As shown above, LCG's do not always use all of the bits in the values they produce. The Java implementation produces 48 bits with each iteration but only returns the 32 most significant bits from these values. This is because the higherorder bits have longer periods than the lower order bits (see below). LCG's that use this technique produce much better values than those that do not.
Advantages and disadvantages of LCGs
LCGs are fast and require minimal memory (typically 32 or 64 bits) to retain state. This makes them valuable for simulating multiple independent streams.
LCGs should not be used for applications where highquality randomness is critical.
Full article ▸
