[−][src]Function wheel_resample::resample_idx
pub fn resample_idx<R, W>(rng: &mut R, weights: &[W], n: usize) -> Vec<usize> where
R: Rng,
W: PartialOrd + Clone + SampleBorrow<W> + SampleUniform + Sized + Zero + AddAssign + SubAssign,
Returns a vector of n indices sampled according to the weights slice.
Example
use wheel_resample::resample_idx; let mut rng = rand::thread_rng(); let weights = [0.1, 0.2, 0.3, 0.8]; let sample_idx = resample_idx(&mut rng, &weights, weights.len()); assert_eq!(sample_idx.len(), weights.len()); let sample_2_idx = resample_idx(&mut rng, &weights, 2); assert_eq!(sample_2_idx.len(), 2);