pub struct FuzzRng { /* private fields */ }Expand description
An RNG that expands a fuzzer byte slice into an infinite deterministic stream.
§Design
FuzzRng maps a fuzzer-controlled byte slice to output blocks.
For each block counter ctr, it:
- Reads a wrapping
u64-wide window from the input bytes. - Xors in
ctrand a domain constant. - Applies a SplitMix64-style finalizer.
input bytes (len = N):
[b0 b1 b2 ... b(N-1)]
block ctr = i:
word_i bytes = [b(i+0)%N, b(i+1)%N, ... b(i+7)%N]
word_i = big-endian u64 of those bytes
out_i = mix64(word_i ^ i ^ DOMAIN)§Why this mapping
Hashing the full input once and then seeding a PRNG makes tiny input changes look globally unrelated. This adapter avoids that by using a sliding window keyed by the block counter.
byte k affects anchors:
i in [k-(BLOCK_BYTES-1), ..., k] (mod N)§Worked Example
With N = 4, input bytes repeat inside each block:
input: [a b c d]
ctr=0: word bytes [a b c d a b c d]
ctr=1: word bytes [b c d a b c d a]
ctr=2: word bytes [c d a b c d a b]
...Even for low-entropy input like [0 0 0 0], output still changes because
ctr is mixed into every block before finalization.
fill_bytes serves output from cached block bytes so callers get a stable
byte stream regardless of whether they request randomness as next_u64,
next_u32, or arbitrary byte slices.
Implementations§
Trait Implementations§
impl TryCryptoRng for FuzzRng
Available on neither
commonware_stability_BETA nor commonware_stability_DELTA nor commonware_stability_EPSILON nor commonware_stability_GAMMA nor commonware_stability_RESERVED.Auto Trait Implementations§
impl Freeze for FuzzRng
impl RefUnwindSafe for FuzzRng
impl Send for FuzzRng
impl Sync for FuzzRng
impl Unpin for FuzzRng
impl UnsafeUnpin for FuzzRng
impl UnwindSafe for FuzzRng
Blanket Implementations§
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
impl<R> CryptoRng for R
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<R> RngCore for Rwhere
R: Rng,
Source§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>,
Return a random value via the
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>,
Generate a random value in the given range. Read more
Source§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 moreSource§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 moreSource§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
Source§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