The misconception
Write down a sequence that is supposed to look like fair coin flips, and many people will alternate heads and tails too often. A run such as six heads in a row feels suspicious, as if a random process should correct itself before that pattern becomes obvious. Genuine independent randomness has no such visual obligation.
Randomness describes a data-generating mechanism, not a requirement that every short output look balanced. Clusters, gaps, and streaks are among the possible outputs. In a long sequence, surprising-looking local patterns have many opportunities to appear.
A second misconception follows the streak: after five heads, tails can feel “due.” If trials are independent and the probability remains fixed, the next flip is not informed by the previous five. The conditional probability of heads on the next trial is still the displayed coin probability.
A synthetic experiment
Use a seeded pseudorandom generator to create sequences of 20, 50, or 100 binary outcomes. Label them H and T, calculate the longest streak, and count the number of runs. A run is one uninterrupted block of the same symbol, so HHHTTH has three runs: HHH, TT, and H.
The generated sequence is synthetic. No physical coin, real-world event, measured process, or human behavior is represented. The seed makes each screen reproducible; changing it displays another valid output from the same programmed mechanism.
Repeat the experiment hundreds or thousands of times and plot the distribution of the longest streak. One sequence with a run of six may look extraordinary in isolation, while the repeated view shows how often comparable runs appear somewhere. Then raise the switch probability above 50% to create an alternating mechanism in which the next outcome is more likely to differ from the previous one. Its total number of heads can still look balanced, but its run count becomes unusually large.
The dedicated random-streaks experiment displays one complete sequence above a histogram of longest runs from repeated sequences. Controls change sequence length, switching probability, and the number of repetitions. Its caption compares the observed mean run count with the value implied by the selected switching mechanism. This is a teaching diagnostic for one specified binary model, not a general randomness validator.
Derivation and reasoning
Independence means that learning previous outcomes does not change the probability assigned to the next outcome. For a fair coin:
P(next H | previous sequence) = 0.5
This remains true after HTHTT, after HHHHH, and after any other sequence with positive probability under the model. The probability of the entire specified sequence HHHHHH is (1/2)^6, but after five heads have already occurred, only one uncertain flip remains. Confusing those two questions creates the “due” intuition.
Runs give one way to assess sequence structure. Suppose a binary sequence contains n1 outcomes of one type and n2 of the other. Under random ordering conditional on those counts, the expected number of runs is:
E(R) = 1 + (2 * n1 * n2) / (n1 + n2)
NIST gives the corresponding variance:
Var(R) = 2*n1*n2*(2*n1*n2 - n1 - n2) / ((n1+n2)^2 * (n1+n2-1))
A standardized runs statistic compares the observed number with this expectation. Too few runs can indicate clustering; too many can indicate excessive alternation. A large-sample normal approximation is commonly used only when both category counts are sufficiently large.
Assumptions
The fair-coin demonstration assumes identical independent Bernoulli trials. A changing probability, serial dependence, intervention, or hidden mixture creates a different model. A runs result is meaningful only relative to the null mechanism that was specified before looking at the sequence.
The browser generator is pseudorandom: a deterministic algorithm turns a seed into a sequence. Reproducibility is useful for education, but it differs from physical unpredictability and does not make the output suitable for security-sensitive use.
The runs test examines one aspect of ordering. A sequence can have an ordinary run count and still contain other forms of dependence. Conversely, testing many patterns and reporting only the most unusual one changes the false-positive rate.
Failure cases
Do not declare a process nonrandom because one recognizable pattern appeared. The probability of a pattern chosen after seeing the data is not the same as the probability of a pattern specified in advance. With enough possible patterns, something memorable will occur.
Do not use the experiment to predict a real-world sequence or recommend a decision strategy. The site uses coin symbols only as a neutral mathematical device for binary outcomes.
Do not interpret a nonsignificant runs test as proof of randomness. Failure to detect a departure may reflect low power or a type of structure the test does not target. NIST also cautions that a statistical test suite cannot by itself certify a generator for cryptographic use.
Source notes
The NIST engineering handbook defines runs, provides their expected value and variance, and explains the large-sample test. NIST SP 800-22 supplies the broader warning that statistical tests are limited diagnostics rather than proof of suitability. This guide uses newly generated browser sequences and does not reproduce a source example.
Keep these distinctions
- Randomness does not require outcomes to alternate or look evenly spaced in a short sequence.
- For independent fair trials, a streak does not change the probability of the next outcome.
- A runs test can detect some departures from randomness but cannot certify randomness.
Sources checked
These sources support the statistical definitions and boundaries. The scenario, prose, calculations, and figure on this page are original to Count & Chance.
- 1.3.5.13. Runs Test for Detecting Non-randomness, National Institute of Standards and Technology. Checked 2026-08-19.
- SP 800-22 Rev. 1: A Statistical Test Suite for Random and Pseudorandom Number Generators, National Institute of Standards and Technology. Checked 2026-08-19.