I’ve just released libRNG v0.1.0. The library is a public domain collection of pseudo-random number generators for C++. It provides several efficient and statistically robust generators. Several of the generators, such as KISS99, pass the TestU01 [pdf] BigCrush battery and should be suitable for most non-cryptographic simulation purposes. Future releases should see sampling from additional distributions, as well as more generators. The library is largely adapted from the public domain C sources in David Jones‘s manuscript Good Practice in (Pseudo) Random Number Generation for Bioinformatics Applications [pdf]. In turn, Jones’s work draws on the prolific work of the late George Marsaglia.

Each class in the library is a subclasses of RNG, overriding either get_uint32() or get_uint64(). I examined buffering RNG output (i.e. asking for a bool consumes one bit of a 32-bit output, rather than truncating the output), but the performance hit, coupled with the extra state seems to make this approach fruitless.

The interface is inspired by Haskell’s System.Random, particularly in the use of split function. Given a generator, split() attempts to return two independent generators. This function is useful when seeding multiple threads with sources of randomness. This function is impractical for RNGs with unnecessarily large state, such as Mersenne Twister, but works splendidly for small generators. split() does not offer any rigorous guarantee of independence. I have a few nascent ideas on offering more robust behavior, but need to do a bit more reading before I can make any promises.

libRNG is used as a source of pseudo-random numbers in Dungeon Crawl Stone Soup v0.8! Crawl’s generator combines an alternating-step generator with KISS. The linear congruential generator is advanced at each step, while a 32-bit Galois linear feedback shift register alternatively advances either the multiply-with-carry generator or the Xorshift generator. The result is marginally faster than KISS, passes BigCrush, and should thwart the sort of cryptanalysis that a player could launch from within the game.

The library is released into the public domain, via Unlicense (or if you prefer, CC0). Contact me if you really need an explicit license for some unforeseen reason (see SQLite’s treatment of this). If you use libRNG, find useful modifications or enhancements, kindly contact me. Bugs should be reported on the project’s issues page.