

Mark Dickinson
Over a year ago
Any thoughts on the PCG family? (E.g., the generator called "PCG RXS M XS 32 (LCG)" in the PCG paper.)
bryc
Over a year ago
@MarkDickinson From what I've seen PCG relies on 64-bit math, and there are no fully 32-bit variants that I can find. I can't find any code specific to the generator you mentioned either. I'm sure PCG is a good generator, but I feel like its a poor choice for JavaScript or embedded systems. xoshiro128** for example is ideal in that regard, since it uses 32-bit integers only.

https://www.pcg-random.org/posts/some-prng-implementations.html

JSF: Bob Jenkins's Small/Fast Chaotic PRNG

The gist jsf.hpp contains an implementation of Bob Jenkins's “Small/Fast PRNG”, which is based on a random invertible mapping—what some call a “chaotic PRNG”. I discussed this generator in a previous post, but the short version is that it passes stringent statistical tests, seems to be quite annoying to predict, and works well. It's also very fast.

My C++ implementation provides the standard jsf64 and jsf32 variants, as well as a number of variations Jenkins suggests that use different constants that should also work well. It also includes some tiny versions, jsf16 and jsf8, which are mostly designed for experimental use (these smaller variants should not be expected to pass extensive statistical tests).

GJrand: David Blackman's Chaotic PRNG

The gist gjrand.hpp contains an implementation of David Blackman's gjrand PRNG, which is based on a random invertible mapping that includes a counter to guarantee no small cycles. I will discuss this generator in a future post, but the short version is that it passes stringent statistical tests, and works well. It's also fast, although not quite as fast as JSF, but on the other hand appears to have slightly stronger bit-mixing properties than JSF.

My C++ implementation provides the standard gjrand64 variant, and at my request Blackman also made a gjrand32 variant. It also includes some tiny versions, gjrand16 and gjrand8, which are mostly designed for experimental use (these smaller variants should not be expected to pass extensive statistical tests). 

SplitMix: 32-Bit and 64-Bit Output from 128-Bit State

The gist splitmix.hpp provides a C++ implementation of SplitMix, as described by Guy L. Steele, Jr., Doug Lea and Christine H. Flood in the paper Fast Splittable Pseudorandom Number Generators and implemented in Java 8 as SplittableRandom (cannonical source code).

This C++ implementation avoids the bugs present in implementations directly derived from the (erroneous) code in the SplitMix paper. Without these bugs it has all properties, good and bad, that are inherent in SplitMix's design (discussed at length in previous posts). In particular, the 64-bit–output variant, splitmix64, may not be suitable for general-purpose use because it has the property that each number is only output once (similar to _once_insecure PCG variants), which can be detected as a deviation from random behavior by statistical tests. The 32-bit–output variant, splitmix32, does not have this issue.

Unlike the other implementations described in this post, this implementation includes both jump-ahead and distance operations (most implementations of SplitMix do not offer these features, although they are quite easy to provide). Also, in contrast to other implementations, the two variants are represented as separate classes (although it is possible to cast between them; splitmix32 is a subclass of splitmix64).

