lcg69069

Crates.iolcg69069
lib.rslcg69069
version0.9.2
sourcesrc
created_at2024-08-03 22:46:48.026771
updated_at2024-08-10 09:33:14.291121
descriptionLCG69069 / MTH$RANDOM Pseudorandom linear congruential generator
homepagehttps://gitlab.com/hsn10/lcg69069
repositoryhttps://gitlab.com/hsn10/lcg69069.git
max_upload_size
id1324571
size17,630
Radim Kolar (hsn10)

documentation

https://docs.rs/lcg69069

README

LCG69069

License Version MSRV Safe Rust no-std ready dependency status Documentation Downloads

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

https://oeis.org/A096552

MCG69069

https://oeis.org/A096551

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.

This code can be used under terms of CC0 or the Unlicense.

Unlicense logo

Commit count: 0

cargo fmt