in lain/src/new_fuzzed.rs [609:660]
fn new_fuzzed<R: crate::rand::Rng>(
mutator: &mut crate::mutator::Mutator<R>,
constraints: Option<&Constraints<Self::RangeType>>,
) -> Self {
trace!("generating random ASCII char");
let min: Self::RangeType;
let max: Self::RangeType;
let weight: Weighted;
// if no min/max were supplied, we'll take a conservative approach of 64 elements
match constraints {
Some(ref constraints) => {
min = constraints.min.unwrap_or(0);
max = constraints.max.unwrap_or(0x80);
weight = constraints.weighted;
}
None => {
// If no constraints were provided, we'll use logic similar to Utf8Char above and
// potentially generate special classes of chars
// even though we could use gen_chance() here, let's not in case we want
// to add more special classes
let mode_chance = mutator.gen_range(0, 100);
match mode_chance {
0..=49 => {
// Just generate a random char
return AsciiChar(mutator.gen_range(0, 0x80) as u8 as char);
}
50..=99 => {
// Characters often used in programming languages
let c = [
' ', ' ', ' ', '\t', '\n', '~', '`', '!', '@', '#', '$', '%', '^', '&',
'*', '(', ')', '_', '-', '=', '+', '[', ']', '{', '}', ':', ';', '\'',
'"', '\\', '|', ',', '<', '>', '.', '/', '?', '0', '1', '2', '3', '4',
'5', '6', '7', '8', '9',
]
.choose(&mut mutator.rng)
.unwrap()
.to_owned();
return AsciiChar(c);
}
_ => unreachable!(),
}
}
}
AsciiChar(
std::char::from_u32(mutator.gen_weighted_range(min as u32, max as u32, weight))
.expect("Invalid codepoint generated for AsciiChar"),
)
}