Sampling a Stream You Can't Store
In short: to pick k items uniformly at random from a stream whose total
length you don't know in advance, keep the first k items, then for every
later item i (0-indexed), draw a random j between 0 and i. If j < k,
that item swaps into slot j of the reservoir; otherwise it's dropped. Item
i ends up with exactly a k / (i + 1) chance of surviving, and working
through the algebra shows every item in the whole stream — no matter when
it arrived — ends up with the same k / n chance of being in the final
reservoir. The reservoir never grows past k items, however long the stream
runs.

Audit a fair sample of a day's requests
Quarry can't store a full day of request logs just to pick a few for a spot-check, but it can prove the sample it does keep is fair by re-running the draw many times and counting how often each request survives:
With 5 requests and a reservoir of 2, every request should appear in roughly
1000 * 2 / 5 = 400 of the 1000 trials. Every seeded trial is
reproducible — the same seed and trial index always draw the same j
values, which is what makes sample_counts itself deterministic even though
each individual draw is random.
Watch one stream of 5 items fill a 2-cell reservoir, replace once, get rejected once, then replace again:
Each later item rolls a random j in [0, i]. j < k swaps it in; j >= k rejects it. The reservoir never grows past k cells.
Item 0, "p", fills the first empty slot — nothing to roll yet. 2 cells. At index 0.