pub struct Source { /* private fields */ }Expand description
Deterministic pseudorandom number generator based on ChaCha8.
Wraps ChaCha8Rng to provide reproducible random sampling for
lattice-based cryptographic operations. Given the same 32-byte seed,
the output sequence is identical across platforms.
Not suitable for cryptographic key generation. This type is intended for deterministic test vectors, noise sampling, and reproducible benchmarks, not for generating secrets.
Implementations§
Source§impl Source
impl Source
Sourcepub fn new(seed: [u8; 32]) -> Source
pub fn new(seed: [u8; 32]) -> Source
Creates a new Source from a 32-byte seed.
The same seed always produces the same pseudorandom sequence.
Sourcepub fn branch(&mut self) -> ([u8; 32], Source)
pub fn branch(&mut self) -> ([u8; 32], Source)
Derives an independent child Source for sub-stream splitting.
Draws a fresh 32-byte seed from self and returns both the seed and
a new Source seeded with it. The parent and child streams are
statistically independent.
Sourcepub fn new_seed(&mut self) -> [u8; 32]
pub fn new_seed(&mut self) -> [u8; 32]
Draws 32 random bytes suitable for use as a derived seed.
Sourcepub fn next_u64n(&mut self, max: u64, mask: u64) -> u64
pub fn next_u64n(&mut self, max: u64, mask: u64) -> u64
Returns a uniformly distributed u64 in [0, max) using rejection
sampling with bitmask mask.
mask should be max.next_power_of_two() - 1 (or wider). Each
iteration draws one u64 and masks it; values >= max are rejected.
Expected iterations: at most 2 when mask is tight.
Sourcepub fn next_i32(&mut self) -> i32
pub fn next_i32(&mut self) -> i32
Returns a uniformly distributed i32 (bit-reinterpretation of a random u32).
Sourcepub fn next_i64(&mut self) -> i64
pub fn next_i64(&mut self) -> i64
Returns a uniformly distributed i64 (bit-reinterpretation of a random u64).
Trait Implementations§
Source§impl TryRng for Source
Implements TryRng by delegating to the inner ChaCha8Rng.
The blanket impl<R: TryRng<Error = Infallible>> Rng for R in rand_core
then provides Rng automatically.
impl TryRng for Source
Implements TryRng by delegating to the inner ChaCha8Rng.
The blanket impl<R: TryRng<Error = Infallible>> Rng for R in rand_core
then provides Rng automatically.
Auto Trait Implementations§
impl Freeze for Source
impl RefUnwindSafe for Source
impl Send for Source
impl Sync for Source
impl Unpin for Source
impl UnsafeUnpin for Source
impl UnwindSafe for Source
Blanket Implementations§
Source§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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<R> RngExt for R
impl<R> RngExt for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§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>,
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator of being
true. Read more