Struct Lcg128Xsl64
pub struct Lcg128Xsl64 { /* private fields */ }
A PCG random number generator (XSL RR 128/64 (LCG) variant).
Permuted Congruential Generator with 128-bit state, internal Linear Congruential Generator, and 64-bit output via "xorshift low (bits), random rotation" output function.
This is a 128-bit LCG with explicitly chosen stream with the PCG-XSL-RR
output function. This combination is the standard pcg64.
Despite the name, this implementation uses 32 bytes (256 bit) space
comprising 128 bits of state and 128 bits stream selector. These are both
set by SeedableRng, using a 256-bit seed.
Note that two generators with different stream parameters may be closely correlated.
Implementations
impl Lcg128Xsl64
fn state(&self) -> u128Current state of the generator
fn stream(&self) -> u128Stream 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: u128, stream: u128) -> 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.
impl Lcg128Xsl64
fn advance(&mut self, delta: u128)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_64()deltanumber of times.fn new(state: u128, stream: u128) -> 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 = 0xa02bdbf7bb3c0a7ac28fa16a64abf96
Trait Implementations
impl Clone for Lcg128Xsl64
fn clone(&self) -> Self
impl Debug for Lcg128Xsl64
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for Lcg128Xsl64
impl PartialEq for Lcg128Xsl64
fn eq(&self, other: &Self) -> bool
impl SeedableRng for Lcg128Xsl64
type Seed = [u8; 32];fn from_seed(seed: Self::Seed) -> SelfWe use a single 255-bit seed to initialise the state and select a stream. One
seedbit (lowest bit ofseed[8]) is ignored.
impl Serialize for Lcg128Xsl64
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where __S: Serializer,
impl StructuralPartialEq for Lcg128Xsl64
impl TryRng for Lcg128Xsl64
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 Lcg128Xsl64
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where __D: Deserializer<'de>,