Function sample_multiple_l_reservoir

Source
pub fn sample_multiple_l_reservoir<'a, Container, R, T>(
    rng: &mut R,
    set: &'a Container,
    requested: usize,
) -> Vec<T>
where R: Rng, Container: HasLen + HasIter<Item<'a> = &'a T>, T: Clone + 'static,
Expand description

Sample multiple random elements uniformly without replacement from a container of known length. If more samples are requested than are in the set, the function returns as many items as it can.

We do not assume the container is randomly indexable, only that it can be iterated over. 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.