# LCG69069 [![License](https://img.shields.io/crates/l/lcg69069)](https://unlicense.org) [![Version](https://img.shields.io/crates/v/lcg69069.svg)](https://crates.io/crates/lcg69069) [![MSRV](https://img.shields.io/crates/msrv/lcg69069?logo=rust&label=MSRV&labelColor=orange)](https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html) [![Safe Rust](https://img.shields.io/badge/Rust-safe-brightgreen.svg)](https://doc.rust-lang.org/nomicon/meet-safe-and-unsafe.html) [![no-std ready](https://img.shields.io/badge/no--std-compatible-limegreen?logo=rust&labelColor=blanchedalmond&logoColor=black)](https://docs.rust-embedded.org/book/intro/no-std.html) [![dependency status](https://deps.rs/repo/gitlab/hsn10/lcg69069/status.svg)](https://deps.rs/repo/gitlab/hsn10/lcg69069) [![Documentation](https://docs.rs/lcg69069/badge.svg)](https://docs.rs/lcg69069) [![Downloads](https://img.shields.io/crates/d/lcg69069)](https://crates.io/crates/lcg69069/versions) [![](https://tokei.rs/b1/gitlab/hsn10/lcg69069?category=code)](https://github.com/XAMPPRocky/tokei) LCG69069 is Pseudo random [Linear congruential generator](https://en.wikipedia.org/wiki/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](https://creativecommons.org/publicdomain/zero/1.0/) or the [Unlicense](https://unlicense.org). ![Unlicense logo](https://unlicense.org/pd-icon.png)