Skip to main content

sample_indices

Function sample_indices 

Source
pub fn sample_indices<R: Rng + ?Sized>(
    rng: &mut R,
    length: usize,
    amount: usize,
) -> Vec<usize>
Expand description

Draws amount distinct indices from 0..length, in random order.

Which of the two algorithms runs is decided by length and amount alone, so it is as reproducible as the draws themselves. Panics if amount exceeds length, or if the pair falls in the range where rand 0.8 used a third algorithm — unreachable for amount == length, which is how every caller here uses it, and better to fail loudly than to diverge quietly.