Crate fuzzerang

source ·
Expand description

Fuzzerang

Useful random generators and distributions for use in fuzzers and mutators

Instead of being very random, very fast, or very secure, these generators and distributions are designed to be useful for fuzzing and mutation by efficiently utilizing available input data. For example, the default [Standard] distribution in the rand crate wastes 31 bits of input for every boolean value generated.

In comparison, StandardBuffered uses the input data more efficiently by consuming only 1 bit for a boolean, the minimum number of bits to generate a value in a range, and so on.

Examples

use fuzzerang::{StandardSeedableRng, StandardBuffered, Ranged};
use rand::{SeedableRng, distributions::Distribution};

// Use a constant seed of 8 bytes, or 64 bits
let mut rng = StandardSeedableRng::from_seed((0..255).take(8).collect());
let dist = StandardBuffered::new();

// We can generate 10 bools from 8 bytes of input because we're only using 1 bit each
for i in 0..10 {
    let x: bool = dist.sample(&mut rng);
    println!("{}: {}", i, x);
}

// In fact, we are so efficient we can generate some alphabetic characters too, which
// each use 4 bits
for i in 0..10 {
    let x: char = dist.sample_range_inclusive(&mut rng, 'A'..='Z');
    println!("{}: {}", i, x);
}

Structs

  • Similar to the rand::distributions::Standard distribution in that it generates values in the “expected” way for each type
  • An RNG that generates values directly from a seed (similar to proptest’s PassThrough RNG). This is mostly only useful in conjunction with the provided distributions like [StandardBuffered] because although the [RandCore] trait is restrictive and only allows byte-level resolution, we want to do better than this.
  • An iterator that generates random values of T with distribution D, using R as the source of randomness.
  • A distribution of values of type S derived from the distribution D by mapping its output of type T through the closure F.

Traits