pub struct ChaChaRng { /* private fields */ }Expand description
ChaCha20-based CSPRNG state. Wraps rand_chacha::ChaCha20Rng
and exposes the same TryRng / SeedableRng surface as the
other vrd backends.
§Examples
use vrd::chacha::ChaChaRng;
let mut rng = ChaChaRng::from_seed([0u8; 32]);
let _ = rng.next_u32();Implementations§
Source§impl ChaChaRng
impl ChaChaRng
Sourcepub fn from_seed(seed: [u8; 32]) -> Self
pub fn from_seed(seed: [u8; 32]) -> Self
Builds a CSPRNG from a deterministic 32-byte seed. Use this
for reproducible tests; use Self::from_os_rng for real
crypto-quality randomness.
§Examples
use vrd::chacha::ChaChaRng;
let mut rng = ChaChaRng::from_seed([1u8; 32]);
assert_ne!(rng.next_u64(), 0);Sourcepub fn from_os_rng() -> Self
pub fn from_os_rng() -> Self
Seeds the CSPRNG from the operating system entropy source.
Requires std.
§Examples
use vrd::chacha::ChaChaRng;
let mut rng = ChaChaRng::from_os_rng();
let _ = rng.next_u32();Sourcepub fn fill_bytes(&mut self, dest: &mut [u8])
pub fn fill_bytes(&mut self, dest: &mut [u8])
Fills dest with CSPRNG-grade random bytes.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ChaChaRng
impl<'de> Deserialize<'de> for ChaChaRng
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 SeedableRng for ChaChaRng
impl SeedableRng for ChaChaRng
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 ChaChaRng
impl TryRng for ChaChaRng
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 Eq for ChaChaRng
impl StructuralPartialEq for ChaChaRng
Auto Trait Implementations§
impl Freeze for ChaChaRng
impl RefUnwindSafe for ChaChaRng
impl Send for ChaChaRng
impl Sync for ChaChaRng
impl Unpin for ChaChaRng
impl UnsafeUnpin for ChaChaRng
impl UnwindSafe for ChaChaRng
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