Struct Lcg128CmDxsm64
pub struct Lcg128CmDxsm64 { /* private fields */ }
A PCG random number generator (CM DXSM 128/64 (LCG) variant).
Permuted Congruential Generator with 128-bit state, internal Linear Congruential Generator, and 64-bit output via "double xorshift multiply" output function.
This is a 128-bit LCG with explicitly chosen stream with the PCG-DXSM
output function. This corresponds to pcg_engines::cm_setseq_dxsm_128_64
from pcg_cpp and PCG64DXSM from NumPy.
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 while two generators with different stream parameter may be closely correlated, this is mitigated by the DXSM output function.
Implementations
impl Lcg128CmDxsm64
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 Lcg128CmDxsm64
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 while two generators with different stream parameter may be closely correlated, this is mitigated by the DXSM output function.
PCG specifies the following default values for both parameters:
state = 0xcafef00dd15ea5e5stream = 0xa02bdbf7bb3c0a7ac28fa16a64abf96
Trait Implementations
impl Clone for Lcg128CmDxsm64
fn clone(&self) -> Lcg128CmDxsm64
impl Debug for Lcg128CmDxsm64
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for Lcg128CmDxsm64
impl PartialEq for Lcg128CmDxsm64
fn eq(&self, other: &Lcg128CmDxsm64) -> bool
impl SeedableRng for Lcg128CmDxsm64
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 Lcg128CmDxsm64
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where __S: Serializer,
impl StructuralPartialEq for Lcg128CmDxsm64
impl TryRng for Lcg128CmDxsm64
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 Lcg128CmDxsm64
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where __D: Deserializer<'de>,
Auto Trait Implementations
impl Freeze for Lcg128CmDxsm64
impl RefUnwindSafe for Lcg128CmDxsm64
impl Send for Lcg128CmDxsm64
impl Sync for Lcg128CmDxsm64
impl Unpin for Lcg128CmDxsm64
impl UnsafeUnpin for Lcg128CmDxsm64
impl UnwindSafe for Lcg128CmDxsm64
Blanket Implementations
impl<R> Rng for Lcg128CmDxsm64
where
R: TryRng<Error = never> + ?Sized,
fn next_u32(&mut self) -> u32fn next_u64(&mut self) -> u64fn fill_bytes(&mut self, dst: &mut [u8])
impl<R> RngCore for Lcg128CmDxsm64
where
R: Rng,
impl<R> TryRngCore for Lcg128CmDxsm64
where
R: TryRng,
type Error = <R as TryRng>::Error;
impl<T> Any for Lcg128CmDxsm64
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Lcg128CmDxsm64
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Lcg128CmDxsm64
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Lcg128CmDxsm64
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> DeserializeOwned for Lcg128CmDxsm64
where
T: for<'de> Deserialize<'de>,
impl<T> From<T> for Lcg128CmDxsm64
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Lcg128CmDxsm64
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Lcg128CmDxsm64
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Lcg128CmDxsm64
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Lcg128CmDxsm64
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>