Function reservoir_sampling::unweighted::r [−][src]
pub fn r<I, T>(stream: I, sample: &mut [T]) where
I: Iterator<Item = T>,
An implementation of algorithm R
(https://en.wikipedia.org/wiki/Reservoir_sampling#Simple_algorithm)
Parameters:
- Type implementing
std::iter::Iterator
as source, - Mutable array slice (i.e.
&mut [T]
) as sample array (i.e. where sampled data is stored) - Type implementing
rand::Rng
for random number generation. In case iterator yields less than sample amount, sample will be filled as much as possible, and returned.