Function rand::seq::index::sample_inplace
source ยท fn sample_inplace<R>(rng: &mut R, length: u32, amount: u32) -> IndexVec
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.