Why it matters

Reservoir sampling handles unknown streams. Powers log sampling, analytics, and ML training pipelines.

Advertisement

The architecture

Fill reservoir with first k.

For item i>k, replace with prob k/i.

Result is uniform over all seen items.

Reservoir sampling flowInitfill reservoir kReplaceprob k/i for i>kUniformover full streamAlgorithm R (Vitter 1985); one-pass, O(k) memory, uniform guarantee
Reservoir sampling flow.
Advertisement

How it works end to end

Algorithm R by Vitter (1985).

One pass, O(k) memory.

Uniform over full stream.