pub fn sample_multiple_l_reservoir<I, R, T>(
rng: &mut R,
iter: I,
requested: usize,
) -> Vec<T>where
R: Rng,
I: IntoIterator<Item = T>,Expand description
Sample multiple random elements uniformly without replacement from a container of unknown length. If more samples are requested than are in the set, the function returns as many items as it can.
The implementation uses Iterator::nth. Randomly indexable structures will have a O(1) nth
implementation and will be very efficient. The values are cloned.
This function implements “Algorithm L” from KIM-HUNG LI Reservoir-Sampling Algorithms of Time Complexity O(n(1 + log(N/n))) https://dl.acm.org/doi/pdf/10.1145/198429.198435
This algorithm is significantly faster than the reservoir algorithm in rand and is
on par with the “known length” algorithm for large requested values.