Algorithms Reservoir Sampling:One Pass When You Do Not Know n Up Front Keep the first k items, then for each later index i (1-based), replace a slot with probability k/i — a uniform sample of k from a stream of unknown length. Read More →