3 ms·
> is it a common problem to have, not knowing the set size? Yes. It could be as simple as receiving values from a Python generator (or equivalent mechanism in
by csl 12y ago
> is it a common problem to have, not knowing the set size?
Yes. It could be as simple as receiving values from a Python generator (or equivalent mechanism in your favourite language), where you don't know the number of items beforehand (and querying for the length is either impossible or expensive).
In such a cases, using reservoir sampling is an elegant solution, because you're probably in a situation where you'll be iterating through all values anyway.