[][src]Function wheel_resample::resample

pub fn resample<R, T, W>(rng: &mut R, weights: &[W], population: &[T]) -> Vec<T> where
    R: Rng,
    T: Clone,
    W: SampleUniform + Float

Returns a vector of weighted samples drawn from the population vector.

Example

use wheel_resample::resample;

let mut rng = rand::thread_rng();
let weights = [0.1, 0.2, 0.3, 0.8];
let population = vec![1, 2, 3, 4];
let samples = resample(&mut rng, &weights, &population);

assert_eq!(samples.len(), population.len());

// Make sure all samples are in the population
assert!(samples.iter().all(|s| population.contains(s)));