Golang Rand
An attempt to house PRNGs under a single roof.
All PRNG sources are either built for 32-bit and 64-bit streams. While Golang's built-in Rand accepts Source interface with an Int63() implementation, we'd re-define it as Uint32(). This way, any sources implemented in the literature should be easy to be translated (directly from either the resource material or the author's code itself) without any bit manipulations/operations involved.
Having a suite of these algorithms would provide Gophers with a reasonable range of tradeoffs among space, time and quality.
Source64 isn't changed. We also added Bool but removed the global methods altogether (since we're not restricted to a single source).
LockedSource is also published.
One important feature is Jumpable and/or streaming sources. Jumping (and Leaping (long jump), not implemented yet) streams are especially important when creating simulations or test reproducibility.
type Source interface {
Uint32() uint32
Bool() bool
Seed(seed int64)
Restart() // Restarts the stream to its initial stream.
}
type JumpableSource interface {
Source
RestartSubstream() // Restarts the stream to the beginning of its current substream.
Jump() // Jumps stream to a specified period-length. (it marks the starting point of a substream)
}
type Source64 interface {
Source
Uint64() uint64
}
Take note that all sources are seeded by SplitMix64.
- JSF (Bob Jenkins's small fast)
- KISS
- LFSR113
- LFSR88
- MRG32k3A
- MRG32k3P
- MT19937
- Multiply-with-Carry
- PCG-MCG XSH-RR (xorshift, random rotate)
- PCG-MCG XSH-RS (xorshift, random shift)
- PCG-LCG XSH-RR (xorshift, random rotate)
- PCG-LCG XSH-RS (xorshift, random shift)
- SFC (Small, Fast, Chaotic)
- WELL512A
- WELL1024A
- WELL19937A
- WELL19937C
- WELL44497A
- WELL44497B
- XoRoShiRo-64*
- XoRoShiRo-64**
- XoShiRo-128+
- XoShiRo-128**
- JSF
- LFSR258
- MRG63K3A
- MT19937
- SFC
- SplitMix-64
- XorShift-1024*
- XoRoShiRo-128+
- XoRoShiRo-128**
- XoShiRo-256+
- XoShiRo-256**
- XoShiRo-512+
- XoShiRo-512**
Some files shows the results from TestU01 battery tests (Crush tests). If you'd like to run the BigCrush tests, you can go to grand-test (This is just a wrapper for L'Ecuyer's TestU01. It takes roughly around 11 hours per implem so be aware).