pub struct Pcg32 { /* private fields */ }Expand description
PCG-XSH-RR-64/32 generator. 16-byte state (one u64 LCG state plus
a 64-bit stream-selecting increment); 32-bit output per call via
XOR-shift-high followed by random rotation.
§Examples
use vrd::pcg::Pcg32;
let mut rng = Pcg32::from_u64_seed(0xCAFE_F00D);
let _ = rng.next_u32();Implementations§
Source§impl Pcg32
impl Pcg32
Sourcepub fn from_seed_stream(seed: u64, stream: u64) -> Self
pub fn from_seed_stream(seed: u64, stream: u64) -> Self
Builds a Pcg32 from a 64-bit seed and a 63-bit stream
selector. Internally bumps the increment to the
nearest odd value to ensure a full-period LCG.
Sourcepub fn from_u64_seed(seed: u64) -> Self
pub fn from_u64_seed(seed: u64) -> Self
Convenience constructor from a single u64 seed; uses the
canonical PCG default stream.
§Examples
use vrd::pcg::Pcg32;
let mut rng = Pcg32::from_u64_seed(42);
assert_ne!(rng.next_u32(), 0);Sourcepub fn next_u32(&mut self) -> u32
pub fn next_u32(&mut self) -> u32
Generates the next random u32.
§Examples
use vrd::pcg::Pcg32;
let mut rng = Pcg32::from_u64_seed(1);
let n = rng.next_u32();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 Pcg32
impl<'de> Deserialize<'de> for Pcg32
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 Pcg32
impl Ord for Pcg32
Source§impl PartialOrd for Pcg32
impl PartialOrd for Pcg32
Source§impl SeedableRng for Pcg32
impl SeedableRng for Pcg32
Source§type Seed = [u8; 16]
type Seed = [u8; 16]
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 Pcg32
impl TryRng for Pcg32
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 Pcg32
impl Eq for Pcg32
impl StructuralPartialEq for Pcg32
Auto Trait Implementations§
impl Freeze for Pcg32
impl RefUnwindSafe for Pcg32
impl Send for Pcg32
impl Sync for Pcg32
impl Unpin for Pcg32
impl UnsafeUnpin for Pcg32
impl UnwindSafe for Pcg32
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