MHN
Add a comment on Hacker News →
1 of 105 comments
  1. Very well put together. If you are curious about the weighted version, I tried to explain it some here: https://gregable.com/2007/10/reservoir-sampling.html

    There's also a distributed version, easy with a map reduce.

    Or the very simple algorithm: generate a random paired for each item in the stream and keep the top N ordered by that random.