Function rand::seq::index::sample_rejection

source ยท
fn sample_rejection<X: UInt, R>(rng: &mut R, length: X, amount: X) -> IndexVec
where R: Rng + ?Sized, IndexVec: From<Vec<X>>,
Expand description

Randomly sample exactly amount indices from 0..length, using rejection sampling.

Since amount <<< length there is a low chance of a random sample in 0..length being a duplicate. We test for duplicates and resample where necessary. The algorithm is O(amount) time and memory.

This function is generic over X primarily so that results are value-stable over 32-bit and 64-bit platforms.