jeremykun.com
Reservoir Sampling
Problem: Given a data stream of unknown size $latex n$, pick an entry uniformly at random. That is, each entry has a $latex 1/n$ chance of being chosen. Solution: (in Python) import random def rese…