The [[wp:linear congruential generator|linear congruential generator]] is a very simple example of a [[random number generator]].
All linear congruential generators use this formula:
*
Where:
* is a seed.
* , , , ..., are the random numbers.
* , , are constants.
If one chooses the values of , and with care, then the generator produces a uniform distribution of integers from to .
LCG numbers have poor quality. and are not independent, as true random numbers would be. Anyone who knows can predict , therefore LCG is not cryptographically secure. The LCG is still good enough for simple tasks like [[Miller-Rabin primality test]], or [[deal cards for FreeCell|FreeCell deals]]. Among the benefits of the LCG, one can easily reproduce a sequence of numbers, from the same . One can also reproduce such sequence with a different programming language, because the formula is so simple.
The task is to replicate two historic random number generators. One is the rand() function from [[:Category:BSD libc|BSD libc]], and the other is the rand() function from the Microsoft C Runtime (MSCVRT.DLL). Each replica must yield the same sequence of integers as the original generator, when starting from the same seed.
In these formulas, the seed becomes . The random sequence is , and so on.
;BSD formula:
*
*
* is in range 0 to 2147483647.
;Microsoft formula:
*
*
* is in range 0 to 32767.
The BSD formula was so awful that FreeBSD switched to a different formula.
More info is at [[Random number generator (included)#C]].