3 releases
0.9.2 | Aug 10, 2024 |
---|---|
0.9.1 | Aug 4, 2024 |
0.9.0 | Aug 3, 2024 |
#629 in Algorithms
51 downloads per month
17KB
183 lines
LCG69069
LCG69069 is Pseudo random Linear congruential generator (LCG) that uses multiplier parameter 69069.
This parameter is proposed by George Marsaglia as a "candidate for the best of all multipliers":
I nominate 69069 = 3 * 7 * 11 * 13 * 23. This palindromically convoluted multiplier is easy to remember and has a nearly cubic lattice for moduli 2^32, 2^35, 2^36.
LCG69069 uses coeficients: multiplier a = 69096, increment c = 1 and modulus m = 2^32.
It can be implemented very quickly on 32-bit hardware in just 2 operations: wrapping multiplication by a and wrapping addition of c. By using 32-bit registers value is automaticaly truncated to correct range; modulus operation is not needed.
Generated values are full 32 bit unsigned integers range with period 2^32.
MTH$RANDOM
LCG69069 is used in the VAX VMS Math library as function MTH$RANDOM and is often known as VAX RANDOM. It is also part of a combined Generator called SUPER-DUPER.
MCG69069
Multiplicative congruential pseudo-random number generator. Its special case of LCG with coeficient c zero. On 32-bit hardware this generator is implemented by single wrapping multiplication operation. This variant is suitable for generating random noise on GPU, see spectral test bellow.
Generated values are full 32 bit unsigned integers range with period 2^30. This is limitation of MCG generators with 2^N modulus, they have /4 period of LCG. LCG generators always perform better than corresponding MCG variants.
References
https://en.wikipedia.org/wiki/Linear_congruential_generator
LCG69069 / VAX MTH$RANDOM
MCG69069
MCG Spectral test
modulus | 2d | 3d | 4d | 5d | 6d | 7d | 8d |
---|---|---|---|---|---|---|---|
2^32 | 0.4625 | 0.3131 | 0.4572 | 0.5529 | 0.3767 | 0.4967 | 0.6852 |
2^35 | 0.6935 | 0.8595 | 0.6347 | 0.7000 | 0.2664 | 0.3690 | 0.5284 |
2^36 | 0.4904 | 0.6822 | 0.7760 | 0.6094 | 0.4746 | 0.3342 | 0.4845 |
The LCG version yields better
spectral test results.
License
This is free and unencumbered software released into the public domain.