Struct rand::distributions::WeightedChoice [] [src]

pub struct WeightedChoice<'a, T: 'a> {
    items: &'a mut [Weighted<T>],
    weight_range: Range<usize>,
}
Unstable (rand)

: use rand from crates.io

A distribution that selects from a finite collection of weighted items.

Each item has an associated weight that influences how likely it is to be chosen: higher weight is more likely.

The Clone restriction is a limitation of the Sample and IndependentSample traits. Note that &T is (cheaply) Clone for all T, as is usize, so one can store references or indices into another vector.

Fields

items
Unstable (rand)

: use rand from crates.io

weight_range
Unstable (rand)

: use rand from crates.io

Methods

impl<'a, T: Clone> WeightedChoice<'a, T>

fn new(items: &'a mut [Weighted<T>]) -> WeightedChoice<'a, T>

Unstable (rand)

: use rand from crates.io

Create a new WeightedChoice.

Panics if: - v is empty - the total weight is 0 - the total weight is larger than a usize can contain.

Trait Implementations

impl<'a, T: Clone> Sample<T> for WeightedChoice<'a, T>

fn sample<R: Rng>(&mut self, rng: &mut R) -> T

impl<'a, T: Clone> IndependentSample<T> for WeightedChoice<'a, T>

fn ind_sample<R: Rng>(&self, rng: &mut R) -> T