Function rand::seq::index::sample_inplace

source ·
fn sample_inplace<R>(rng: &mut R, length: u32, amount: u32) -> IndexVecwhere
    R: Rng + ?Sized,
Expand description

Randomly sample exactly amount indices from 0..length, using an inplace partial Fisher-Yates method. Sample an amount of indices using an inplace partial fisher yates method.

This allocates the entire length of indices and randomizes only the first amount. It then truncates to amount and returns.

This method is not appropriate for large length and potentially uses a lot of memory; because of this we only implement for u32 index (which improves performance in all cases).

Set-up is O(length) time and memory and shuffling is O(amount) time.