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§
Source§impl RngCore for FuzzRng
impl RngCore for FuzzRng
Source§fn fill_bytes(&mut self, dest: &mut [u8])
fn fill_bytes(&mut self, dest: &mut [u8])
Fill
dest with random data. Read moreimpl CryptoRng for FuzzRng
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
Source§impl<T> CryptoRngCore for T
impl<T> CryptoRngCore for T
Source§fn as_rngcore(&mut self) -> &mut dyn RngCore
fn as_rngcore(&mut self) -> &mut dyn RngCore
Upcast to an
RngCore trait object.Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,
Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_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 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) -> DistIter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Create an iterator that generates values using the given distribution. Read more
Source§fn gen_bool(&mut self, p: f64) -> bool
fn gen_bool(&mut self, p: f64) -> bool
Return a bool with a probability
p of being true. Read moreSource§fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
Return a bool with a probability of
numerator/denominator of being
true. I.e. gen_ratio(2, 3) has chance of 2 in 3, or about 67%, of
returning true. If numerator == denominator, then the returned value
is guaranteed to be true. If numerator == 0, then the returned
value is guaranteed to be false. Read more