count_and_sample_single_l_reservoir

Function count_and_sample_single_l_reservoir 

Source
pub fn count_and_sample_single_l_reservoir<I, R, T>(
    rng: &mut R,
    iterable: I,
) -> (usize, Option<T>)
where R: Rng, I: IntoIterator<Item = T>,
Expand description

Count elements and sample one element uniformly from an iterator of unknown length.

Returns (count, sample) where count is the total number of items observed and sample is None iff count == 0.

This uses single-item reservoir sampling while tracking total count.