Trait libafl_bolts::rands::Rand

source ·
pub trait Rand: Debug + Serialize + DeserializeOwned {
    // Required methods
    fn set_seed(&mut self, seed: u64);
    fn next(&mut self) -> u64;

    // Provided methods
    fn below(&mut self, upper_bound_excl: u64) -> u64 { ... }
    fn between(&mut self, lower_bound_incl: u64, upper_bound_incl: u64) -> u64 { ... }
    fn choose<I, E, T>(&mut self, from: I) -> T
       where I: IntoIterator<Item = T, IntoIter = E>,
             E: ExactSizeIterator + Iterator<Item = T> { ... }
}
Expand description

Ways to get random around here. Please note that these are not cryptographically secure. Or, even if some might be by accident, at least they are not seeded in a cryptographically secure fashion.

Required Methods§

source

fn set_seed(&mut self, seed: u64)

Sets the seed of this Rand

source

fn next(&mut self) -> u64

Gets the next 64 bit value

Provided Methods§

source

fn below(&mut self, upper_bound_excl: u64) -> u64

Gets a value below the given 64 bit val (exclusive)

source

fn between(&mut self, lower_bound_incl: u64, upper_bound_incl: u64) -> u64

Gets a value between the given lower bound (inclusive) and upper bound (inclusive)

source

fn choose<I, E, T>(&mut self, from: I) -> T
where I: IntoIterator<Item = T, IntoIter = E>, E: ExactSizeIterator + Iterator<Item = T>,

Choose an item at random from the given iterator, sampling uniformly.

Note: the runtime cost is bound by the iterator’s nth implementation

  • For Vec, slice, array, this is O(1)
  • For HashMap, HashSet, this is O(n)

Object Safety§

This trait is not object safe.

Implementors§