Calculateus

Runs Test for Randomness Calculator

Test whether a binary sequence shows statistically significant patterns, using the Wald-Wolfowitz runs test.

Result

Number of Runs
9
Expected Runs
8.47
Z-Statistic
0.287

A z-statistic beyond ±1.96 suggests the sequence is not random at the 95% confidence level - too few runs suggests clustering, too many suggests alternating too regularly.

About the Runs Test

This calculator runs the Wald-Wolfowitz runs test on a binary sequence, such as wins and losses, heads and tails, or up and down price days, to check whether the order of values looks statistically random or shows a detectable pattern of clustering or alternation. It is a nonparametric test that only looks at the sequence of runs, not the values' magnitude.

How It Works

You paste a sequence containing exactly two distinct values, separated by commas or spaces. The calculator counts the total number of runs (unbroken streaks of the same value), then compares that count to the number of runs you would expect under a truly random ordering given how many of each value appear. The result is a z-statistic measuring how far the observed run count deviates from that expectation.

Runs = count of consecutive same-value streaks. Expected Runs = (2 x countA x countB) / (countA + countB) + 1. Variance = [2 x countA x countB x (2 x countA x countB - countA - countB)] / [(countA + countB)^2 x (countA + countB - 1)]. Z = (Runs - Expected Runs) / sqrt(Variance).

Formula & Methodology

Count each value's total occurrences (countA and countB) and count the total runs by scanning the sequence and incrementing whenever consecutive values differ, starting the count at 1. Plug both counts into the expected-runs and variance formulas above, then subtract expected from observed runs and divide by the square root of the variance to get the z-statistic.

Examples

Default 15-value sequence

For the sequence 1,1,0,1,0,0,0,1,1,0,1,0,0,1,1 (8 ones, 7 zeros), there are 9 runs against an expected 8.47, giving a variance of about 3.45 and a z-statistic of roughly 0.29, well inside the ±1.96 range, so the ordering looks consistent with randomness.

Perfectly alternating sequence

For 1,0,1,0,1,0,1,0,1,0 (5 ones, 5 zeros), every adjacent pair differs, producing 10 runs against an expected 6, a variance of about 2.22, and a z-statistic near 2.68, which exceeds ±1.96 and flags the sequence as alternating far more than chance would predict.

Advantages

  • Detects patterns in ordering that a simple frequency count of each value would completely miss.
  • Requires no assumption about the underlying distribution, since it works purely from the sequence of runs.
  • Distinguishes between two opposite failure modes, clustering (too few runs) and over-alternation (too many runs), rather than lumping both into a single generic flag.

Common Mistakes

  • Treating a non-significant z-statistic as proof the sequence is truly random, when it only means the test found no detectable pattern in this particular check.
  • Running the test on a sequence with more than two distinct categories without first collapsing it into a binary form, which the calculator will reject as invalid input.
  • Ignoring the sign of the z-statistic, which distinguishes a clustering pattern (negative, too few runs) from an alternating pattern (positive, too many runs).

Edge Cases to Watch For

  • The sequence must contain at least 4 values and exactly 2 distinct values; anything else returns an input error.
  • If the computed variance is zero or negative, the calculator returns an error asking for a longer or more balanced sequence, since the z-statistic cannot be computed in that case.
  • A z-statistic beyond about ±1.96 is treated as evidence against randomness at the 95% confidence level; too few runs indicates clustering, too many indicates over-regular alternation.
  • The test only evaluates the order of the two values, not their frequency balance, so a sequence with an unusual mix of the two values can still test as random if the order itself is unpatterned.

Common Use Cases

  • Analysts checking whether a sequence of trading days, coin flips, or quality-control pass/fail results shows hidden patterning.
  • Auditors and quality assurance teams screening data entry logs or randomization procedures for unexpected regularity.
  • Statistics students and researchers verifying that a random number generator or sampling process produced a genuinely unordered sequence.
Written & fact-checked by the Calculateus TeamLast updated August 5, 2026How we verify our formulas

Frequently asked questions

What does a runs test detect?

It checks whether a binary sequence's pattern of consecutive same-value 'runs' is consistent with a random process - far fewer runs than expected suggests the values cluster together (positive autocorrelation), while far more runs than expected suggests they alternate more than chance would predict.

Conclusion

The runs test gives a quick, distribution-free way to check whether a binary sequence's ordering looks random or shows a detectable streak pattern. The z-statistic and the ±1.96 reference point make it straightforward to interpret without deeper statistical background.