seq::[−][src] index:: sample
pub fn sample<R>(rng: &mut R, length: usize, amount: usize) -> IndexVec where
R: Rng + ?Sized,
Randomly sample exactly
amount distinct indices from
return them in random order (fully shuffled).
This method is used internally by the slice sampling methods, but it can sometimes be useful to have the indices themselves so this is provided as an alternative.
The implementation used is not specified; we automatically select the
fastest available algorithm for the
(based on detailed profiling on an Intel Haswell CPU). Roughly speaking,
O(amount), except that when
amount is small, performance
is closer to
O(amount^2), and when
length is close to
Note that performance is significantly better over
u32 indices than over
u64 indices. Because of this we hide the underlying type behind an
If an allocation-free
no_std function is required, it is suggested
to adapt the internal
amount > length.