Xorshift32 (Marsaglia, "Xorshift RNGs", J. More...
#include <rng.hpp>
Public Member Functions | |
| constexpr | Xorshift32 ()=default |
| constexpr | Xorshift32 (std::uint32_t s) |
| void | seed (std::uint32_t s) |
| void | set_seed (std::uint32_t s) |
| Compatibility spelling used by the Round 2 DSP blocks. | |
| void | reset () |
| Rewind to the seeded stream position. | |
| std::uint32_t | next_u32 () |
| std::uint32_t | next_uint () |
| Compatibility spelling used by the Round 2 DSP blocks. | |
| float | next_unipolar () |
| Uniform in [0, 1). | |
| float | next_bipolar () |
| Uniform in [-1, 1). | |
| template<typename T> | |
| T | next_bipolar () |
| float | next_unit () |
| Uniform in [0, 1), with the caller-selected result precision. | |
| template<typename T> | |
| T | next_unit () |
| float | gaussian () |
| Standard normal via the polar-free Box-Muller transform (Box & Muller, Ann. | |
| std::uint32_t | state () const |
| std::uint32_t | seed () const |
Static Public Attributes | |
| static constexpr std::uint32_t | kDefaultSeed = 0x9E3779B9u |
| Any nonzero constant works; this is the 32-bit golden-ratio odd constant, which is also what seed(0) normalizes to. | |
Xorshift32 (Marsaglia, "Xorshift RNGs", J.
Stat. Soft. 8(14), 2003) with the canonical 13/17/5 triple.
Zero is the generator's fixed point — a zero-initialized instance would emit zeros forever — so the state is defaulted to a nonzero constant and a zero state is repaired lazily on use. That keeps "zero-init = fresh" true for aggregates that embed this without a constructor call.
|
constexprdefault |
|
inlineexplicitconstexpr |
|
inline |
Standard normal via the polar-free Box-Muller transform (Box & Muller, Ann.
Math. Statist. 29(2), 1958). The transform produces two independent deviates per pair of uniforms; the second is cached so the amortized cost is one log/sqrt/sincos pair every other call.
u1 is drawn on (0, 1] rather than [0, 1) — log(0) is the one input that breaks the transform.
|
inline |
|
inline |
Uniform in [-1, 1).
|
inline |
|
inline |
Compatibility spelling used by the Round 2 DSP blocks.
|
inline |
Uniform in [0, 1).
Built from the top 24 bits so every result is exactly representable in float and the spacing is uniform.
|
inline |
|
inline |
Uniform in [0, 1), with the caller-selected result precision.
|
inline |
Rewind to the seeded stream position.
reset() restores the seed the caller set, not the default one — a reset that silently discarded the seed would make every seeded object share one stream, which is the opposite of what seeding is for.
|
inline |
|
inline |
|
inline |
Compatibility spelling used by the Round 2 DSP blocks.
|
inline |
|
staticconstexpr |
Any nonzero constant works; this is the 32-bit golden-ratio odd constant, which is also what seed(0) normalizes to.