Struct Lcg64Xsh32
pub struct Lcg64Xsh32 { /* private fields */ }
A PCG random number generator (XSH RR 64/32 (LCG) variant).
Permuted Congruential Generator with 64-bit state, internal Linear Congruential Generator, and 32-bit output via "xorshift high (bits), random rotation" output function.
This is a 64-bit LCG with explicitly chosen stream with the PCG-XSH-RR
output function. This combination is the standard pcg32.
Despite the name, this implementation uses 16 bytes (128 bit) space
comprising 64 bits of state and 64 bits stream selector. These are both set
by SeedableRng, using a 128-bit seed.
Note that two generators with different stream parameter may be closely correlated.
Implementations
impl Lcg64Xsh32
fn advance(&mut self, delta: u64)Multi-step advance functions (jump-ahead, jump-back)
The method used here is based on Brown, "Random Number Generation with Arbitrary Stride,", Transactions of the American Nuclear Society (Nov. 1994). The algorithm is very similar to fast exponentiation.
Even though delta is an unsigned integer, we can pass a signed integer to go backwards, it just goes "the long way round".
Using this function is equivalent to calling
next_32()deltanumber of times.fn new(state: u64, stream: u64) -> SelfConstruct an instance compatible with PCG seed and stream.
Note that the highest bit of the
streamparameter is discarded to simplify upholding internal invariants.Note that two generators with different stream parameters may be closely correlated.
PCG specifies the following default values for both parameters:
state = 0xcafef00dd15ea5e5stream = 0xa02bdbf7bb3c0a7
impl Lcg64Xsh32
fn state(&self) -> u64Current state of the generator
fn stream(&self) -> u64Stream parameter of the generator
Note that PCG only stores an increment, which is always odd.
Self::from_statediscards the highest bit from the stream by shifting it to the left, so this method shifts the increment by one bit to the right.fn from_state(state: u64, stream: u64) -> SelfConstruct an instance using a pre-initialized
stateUnlike
Self::new, this method does not mutatestate. It may therefore be used withSelf::stateandSelf::streamto reconstruct an RNG.Note that the highest bit of the
streamparameter is discarded to simplify upholding internal invariants.
Trait Implementations
impl Clone for Lcg64Xsh32
fn clone(&self) -> Self
impl Debug for Lcg64Xsh32
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for Lcg64Xsh32
impl PartialEq for Lcg64Xsh32
fn eq(&self, other: &Self) -> bool
impl SeedableRng for Lcg64Xsh32
type Seed = [u8; 16];fn from_seed(seed: Self::Seed) -> SelfWe use a single 127-bit seed to initialise the state and select a stream. One
seedbit (lowest bit ofseed[8]) is ignored.
impl Serialize for Lcg64Xsh32
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where __S: Serializer,
impl StructuralPartialEq for Lcg64Xsh32
impl TryRng for Lcg64Xsh32
type Error = never;fn try_next_u32(&mut self) -> Result<u32, Infallible>fn try_next_u64(&mut self) -> Result<u64, Infallible>fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Infallible>
impl<'de> Deserialize<'de> for Lcg64Xsh32
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where __D: Deserializer<'de>,