Expand description
An efficient data structure to sample from a discrete, fixed distribution.
use fuzzcheck::mutators::vose_alias::VoseAlias;
// the discrete distribution is a vector of floats which must add up to 1.0
let probabilities = vec![0.5, 0.1, 0.2, 0.2];
// create the Vose alias. The `probabilities` vector is moved to `alias.original_probabilities`.
let alias = VoseAlias::new(probabilities);
// index has a 50% chance of being 0, 10% chance of being 1, 20% chance of being 2, and 20% chance of being 2
let index = alias.sample();
assert!((0 .. 4).contains(&index));
Fields
original_probabilities: Vec<f64>
Implementations
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for VoseAlias
impl Send for VoseAlias
impl !Sync for VoseAlias
impl Unpin for VoseAlias
impl UnwindSafe for VoseAlias
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more