pub struct Pcg64 { /* private fields */ }Expand description
PCG-XSL-RR-128/64 generator. 32-byte state (one u128 LCG state
plus a 128-bit increment); 64-bit output per call via
XOR-shift-low followed by random rotation.
§Examples
use vrd::pcg::Pcg64;
let mut rng = Pcg64::from_u128_seed(0xCAFE_F00D);
let _ = rng.next_u64();Implementations§
Source§impl Pcg64
impl Pcg64
Sourcepub fn from_seed_stream(seed: u128, stream: u128) -> Self
pub fn from_seed_stream(seed: u128, stream: u128) -> Self
Builds a Pcg64 from a 128-bit seed and a 127-bit stream
selector. The increment is bumped to the nearest odd value
to ensure a full-period LCG.
Sourcepub fn from_u128_seed(seed: u128) -> Self
pub fn from_u128_seed(seed: u128) -> Self
Convenience constructor from a single u128 seed using the
canonical PCG default stream.
§Examples
use vrd::pcg::Pcg64;
let mut rng = Pcg64::from_u128_seed(42);
assert_ne!(rng.next_u64(), 0);Sourcepub fn next_u64(&mut self) -> u64
pub fn next_u64(&mut self) -> u64
Generates the next random u64.
§Examples
use vrd::pcg::Pcg64;
let mut rng = Pcg64::from_u128_seed(1);
let n = rng.next_u64();Sourcepub fn fill_bytes(&mut self, dest: &mut [u8])
pub fn fill_bytes(&mut self, dest: &mut [u8])
Fills dest with random bytes.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Pcg64
impl<'de> Deserialize<'de> for Pcg64
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Pcg64
impl Ord for Pcg64
Source§impl PartialOrd for Pcg64
impl PartialOrd for Pcg64
Source§impl SeedableRng for Pcg64
impl SeedableRng for Pcg64
Source§type Seed = [u8; 32]
type Seed = [u8; 32]
Seed type, which is restricted to types mutably-dereferenceable as
u8
arrays (we recommend [u8; N] for some N). Read more§fn seed_from_u64(state: u64) -> Self
fn seed_from_u64(state: u64) -> Self
Create a new PRNG using a
u64 seed. Read more§fn from_rng<R>(rng: &mut R) -> Selfwhere
R: Rng + ?Sized,
fn from_rng<R>(rng: &mut R) -> Selfwhere
R: Rng + ?Sized,
Create a new PRNG seeded from an infallible
Rng. Read moreSource§impl TryRng for Pcg64
impl TryRng for Pcg64
Source§type Error = Infallible
type Error = Infallible
The type returned in the event of a RNG error. Read more
Source§fn try_next_u32(&mut self) -> Result<u32, Self::Error>
fn try_next_u32(&mut self) -> Result<u32, Self::Error>
Return the next random
u32.Source§fn try_next_u64(&mut self) -> Result<u64, Self::Error>
fn try_next_u64(&mut self) -> Result<u64, Self::Error>
Return the next random
u64.impl Copy for Pcg64
impl Eq for Pcg64
impl StructuralPartialEq for Pcg64
Auto Trait Implementations§
impl Freeze for Pcg64
impl RefUnwindSafe for Pcg64
impl Send for Pcg64
impl Sync for Pcg64
impl Unpin for Pcg64
impl UnsafeUnpin for Pcg64
impl UnwindSafe for Pcg64
Blanket Implementations§
§impl<R> TryRngCore for Rwhere
R: TryRng,
impl<R> TryRngCore for Rwhere
R: TryRng,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<R> Rng for Rwhere
R: TryRng<Error = Infallible> + ?Sized,
impl<R> Rng for Rwhere
R: TryRng<Error = Infallible> + ?Sized,
§impl<R> RngExt for Rwhere
R: Rng + ?Sized,
impl<R> RngExt for Rwhere
R: Rng + ?Sized,
§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
Return a random value via the
StandardUniform distribution. Read more§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>where
Self: Sized,
StandardUniform: Distribution<T>,
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>where
Self: Sized,
StandardUniform: Distribution<T>,
§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Generate a random value in the given range. Read more
§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
Return a bool with a probability
p of being true. Read more§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
Return a bool with a probability of
numerator/denominator of being
true. Read more§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Sample a new value, using the given distribution. Read more
§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Create an iterator that generates values using the given distribution. Read more