Python snippet to sample from a (finite) stream of unknown size at random.

Reservoir Sampling
jeremykun.com