#rand #mcg #no-std

no-std minstd

MINSTD minimal standard random number generator

5 releases

0.9.4 Aug 8, 2024
0.9.3 Aug 8, 2024
0.9.2 Aug 8, 2024
0.9.1 Aug 5, 2024
0.9.0 Aug 5, 2024

#978 in Algorithms


Used in walkup

Unlicense OR CC0-1.0

18KB
284 lines

MINSTD

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

This multiplicative congruential pseudo random number generator is called "The minimal standard generator" or MCG16807. First described in 1988 Park and Miller paper Random number generators: Good ones are hard to find.

Generator modulus m = 2^31-1 is Mersene prime M31. The multiplier a = 7^5 = 16807 was first suggested by Lewis, Goodman and Miller in 1969.

Multiplicative congruential generators of this form are ascribed to D. H. Lehmer and they are know as Lehmer random number generators. First described by Hutchinson and independently by Downham and Roberts.

Generator was later criticized by Marsaglia and Sullivan (1993). While it is still in use today (in particular: in CarbonLib, in Matlab as mcg16807, FreeBSD 5 as rand() and in C++11 as function minstd_rand0) Park, Miller and Stockmeyer "officially" since July 1990 advocate a = 48271 multiplier.

Updated version performs much better in Spectral test where performs very well up to 6th dimension.

Minimalistic code

This code have no dependencies and is not using standard library. Can be used in embedded or webasm environments.

MINSTD / 1990 version

Multiplier 48271

https://oeis.org/A221556

MINSTD0 / 1988 version

Multiplier 16807

https://oeis.org/A096550

Spectral test

multiplier 2d 3d 4d 5d 6d 7d 8d
16807 0.3375 0.4412 0.5752 0.7361 0.6454 0.5711 0.6096
48271 0.8960 0.8269 0.8506 0.7332 0.8078 0.5865 0.4364
69621 0.7836 0.9205 0.8516 0.7318 0.7667 0.6628 0.7845

Value 0.75 or higher is considered good enough to pass spectral test.

License

This is free and unencumbered software released into the public domain.

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

Unlicense logo

No runtime deps