#include <xor_shift.h>
Public Member Functions | |
XorShiftStarRng64 (uint64_t initial_seed) | |
void | Get (ByteSpan dest) final |
void | InjectEntropyBits (uint32_t data, uint_fast8_t num_bits) final |
![]() | |
template<class T > | |
void | GetInt (T &dest) |
template<class T > | |
void | GetInt (T &dest, const T &exclusive_upper_bound) |
virtual void | Get (ByteSpan dest)=0 |
virtual void | InjectEntropyBits (uint32_t data, uint_fast8_t num_bits)=0 |
void | InjectEntropy (ConstByteSpan data) |
Injects entropy into the pool byte-by-byte. | |
A random generator based off the xorshift* algorithm.
The state is represented as an integer that, with each generation, performs exclusive OR (XOR) operations on different left/right bit shifts of itself. The *
in xorshift*
refers to a final multiplication that is applied to the output value. The final multiplication is essentially a nonlinear transformation that makes the algorithm stronger than a plain XOR shift.
Pigweed's implementation augments xorshift*
with an ability to inject entropy to reseed the generator throughout its lifetime. When entropy is injected, the results of the generator are no longer completely deterministic based on the original seed.
See also Xorshift RNGs and An experimental exploration of Marsaglia's xorshift generators, scrambled.
|
inlinefinalvirtual |
Populates the destination buffer with a randomly generated value.
This generator uses entropy-seeded PRNG to never exhaust its random number pool.
Implements pw::random::RandomGenerator.
|
inlinefinalvirtual |
Injects entropy by rotating the state by the number of entropy bits before XORing the entropy with the current state.
This technique ensures that seeding the random value with single bits will progressively fill the state with more entropy.
Implements pw::random::RandomGenerator.