A growing robot record stream can be too long to retain in full, while its final length is not known when early records arrive. Keeping one uniformly selected record does not require guessing that length. A changing replacement probability gives every observed record the same chance at each fixed prefix, despite the newer records having fewer opportunities to be overwritten.
The target here is one unweighted record identity, not one unique value, one time interval, or a representative physical condition. The stream examples and probability calculations are invented. No logger, random-number generator, reservoir library, or deployment was executed.
Define the single-slot rule
Label incoming records by arrival identities 1, 2, 3, and so on. Store record 1 initially. When record i arrives for i greater than one, draw an independent uniform integer from 1 through i. Replace the stored record with i only if that integer is one; otherwise retain the current record.
Thus record i is admitted with probability 1/i. The algorithm stores one record and a count of arrivals. Its record-storage capacity stays one, although an exact counter for an arbitrarily large stream still needs enough bits to represent the count. Unknown final length does not mean that the count can be discarded.
NIST's official dictionary gives the general reservoir replacement algorithm and equal-subset guarantee. Apache DataSketches documents uniform sampling of unweighted streams and how duplicate input items remain separate update opportunities. The proofs and numerical streams below develop the one-slot case independently.
Prove equal probability at a fixed prefix
Fix a deterministic prefix length n. For record j greater than one to remain selected at the end, it must first enter with probability 1/j and then survive every later arrival i. Its survival chance at step i is 1 - 1/i = (i-1)/i.
The final probability is therefore (1/j) times the product j/(j+1), (j+1)/(j+2), through (n-1)/n. The factors telescope to j/n, leaving 1/n. Record 1 begins in the slot with probability one; its survival product 1/2 times 2/3 through (n-1)/n also equals 1/n.
For n = 5, record 2 survives with probability (1/2)(2/3)(3/4)(4/5) = 1/5. Record 4 has probability (1/4)(4/5) = 1/5. The last record enters with probability 1/5 and faces no later replacement. The differing admission and survival terms produce the same final result for every identity.
An induction gives another perspective. Assume each previous record has probability 1/(i-1) immediately before arrival i. It survives the new update with probability (i-1)/i, yielding 1/i. The newcomer also receives probability 1/i. The uniform property is restored after every update rather than only at a preselected final size.
A constant replacement chance favors recent records
Consider a shortcut that replaces the slot with probability one-half at every arrival after the first. After five records, the final probabilities for identities 1 through 5 are 1/16, 1/16, 1/8, 1/4, and 1/2.
The fifth record receives a much larger chance because it cannot be overwritten. The first record must survive four successive decisions. Random replacement alone therefore does not establish uniform sampling; the replacement schedule must compensate for each record's remaining exposure to future updates.
Uniform records do not mean uniform values
Suppose five distinct arrivals carry values red, red, blue, red, blue. A correct single-slot reservoir selects each arrival identity with probability 1/5. The probability of a red value is consequently 3/5, while blue has probability 2/5.
It does not select the two distinct color names with equal probability. Deduplicating values before sampling would change the population being sampled. Conversely, identical payload bytes can belong to different legitimate arrivals, so an equality comparison on values alone cannot identify which record opportunity was selected.
Repeated outputs also are not independent samples. The reservoir after record 5 and after record 6 share history, and with probability 5/6 the sixth update leaves the same stored identity. Querying one maintained reservoir twice does not create two independent draws from an unchanged population.
State the stopping boundary
The proof above applies to every fixed observed prefix. It also permits a stopping choice independent of the reservoir's random decisions, with appropriate conditioning on that prefix. A sample-dependent stopping rule can invalidate a stronger conditional claim about the final stream length.
For a small counterexample, process two records and stop immediately if identity 1 is in the slot. Otherwise process record 3 and stop. The event that the final length is two implies that the stored identity is 1 with certainty. Conditional on that length, it is not a uniform choice between identities 1 and 2.
Unconditionally, the final probabilities are 1/2 for identity 1, 1/3 for identity 2, and 1/6 for identity 3. This does not contradict the fixed-prefix proof: the rule selected which prefix to report using the sample itself. The stream boundary and sampling rule need to be described together.
What the sample represents
Uniformity treats every admitted record as one equal opportunity. If recording frequency changes, uniform records need not mean uniform elapsed time. If a logging stage omits events, the reservoir cannot reconstruct the missing population. Weighted selection is a different problem from the unweighted rule proved here.
For a reproducible sampling record, keep the identity convention, arrival count, capacity, random-choice rule, and stopping boundary. The mathematical guarantee then has a clear object: one equally likely identity from a stated prefix, obtained with a bounded record buffer while the final stream length remains unknown.
Sources checked October 24, 2026:
NIST Dictionary of Algorithms and Data Structures: reservoir sampling: https://xlinux.nist.gov/dads/HTML/reservoirSampling.html
Apache DataSketches: Reservoir Sampling Sketches: https://datasketches.apache.org/docs/Sampling/ReservoirSamplingSketches.html
Image caption: Concept illustration from the site media library. Robot beside laptop displaying workflow; conceptual data preparation context. This scene does not depict the mathematical inputs or an executed hardware or software experiment.