Hacker News new | ask | show | jobs
by tyrust 85 days ago
If you break early, then you haven't given items later in the list the chance to be selected. You need to go through the entire list in order for every item to have an equal probability of selection.

I didn't get it at first, either, and the Wikipedia article didn't do it for me. This explanation finally got me there: https://florian.github.io/reservoir-sampling/

1 comments

But wouldn't changing the probability be even more random?
If you read the "Adapting Probabilities" section of the link above, there's a nice explanation of why changing the probability works.