Math calculator

Runs Test Calculator

Whether a sequence is ordered by chance — counts held fixed.

Order, and only order

2 runs where 11 are expected. z = −3.9055, p = 0.000094 — and the counts are exactly ten and ten.

20 values — 10 ones and 10 zeros

2 runs, z = -3.90548, p = 0.000094

A random sequence with these counts would average 11.0000 runs. Yours has fewer, which means the symbols cluster — the same value repeats more than chance allows.

Runs observed

2

blocks of identical values

Runs expected

11.00000

2n₁n₂/n + 1

z statistic

-3.90548

continuity corrected

p-value

0.000094

two-sided

Ones / zeros

10 / 10

the test ignores this

Standard deviation of runs

2.17643

under randomness

Direction

Clustered

too few changes

Longest run

10

the test does not use it

11111111110000000000

Each amber divider is a change of symbol — a run boundary. Count them and add one and you have the statistic. That is the entire test, and it explains why shuffling the sequence changes everything while the counts stay fixed.

Detecting the bias people actually have

Asked to produce a random sequence, people switch too often — a long repeat feels “non-random”. Simulated at 800 replications per row, n = 100, with the switch probability raised above the fair 0.5.

Runs-test detection rate against the probability of switching symbol
Switch probabilityMean runsExpected under randomnessDetected at α = 0.05
0.50 (fair)50.8450.543.1%
0.6060.7450.6650.4%
0.7070.5850.7898.1%
0.8080.3550.88100.0%

A genuinely fair sequence is flagged only about 3% of the time. A mild over-alternation of 0.6 is caught roughly half the time at n = 100, and 0.7 almost always. This is the test’s classic use: distinguishing a fabricated sequence from a real one, where the counts are perfectly plausible and the order is not.

The counts are held fixed, which is what makes the test possible. Expected runs are 2n₁n₂/n + 1 — a function of the counts alone — so the test asks only whether your ARRANGEMENT of those counts is surprising. A frequency test asks the opposite question and cannot see any of this.
Too few runs and too many are both failures of randomness. Clustering means the process has memory — a trend, autocorrelation, a batch effect. Over-alternation usually means the sequence was constructed rather than observed. The test is two-sided because both are real, and it names which one it found.
Numbers become a sequence by splitting at the median. That converts a question about a measurement series into one about a binary string, which is how the test is used for process control: a drifting process produces a long block above the median followed by a long block below, and the runs count collapses.

What this tool shows

Ten 1s followed by ten 0s gives z = −3.9055; perfect alternation gives z = +3.9055. Identical counts — ten of each — and mirror-image results, because this test reads ORDER and nothing else. It is the one thing a frequency test cannot see, and it is how a fabricated sequence is told from a real one.

  • The Wald-Wolfowitz runs test with and without the continuity correction
  • Every run boundary drawn, so the statistic is countable by eye
  • Numbers accepted directly and split at their median
  • The direction named: clustering or over-alternation
  • A measured detection table for the human over-alternation bias
  • Expected runs and their standard deviation under randomness
Order only Boundaries drawn Two-sided Median split

The counts are held fixed. Only the arrangement is tested.

Updated 12 September 2026 · Works in any browser, no installation

A run is a block of identical consecutive values, and the test asks whether you have too few or too many of them. Too few means the sequence clusters — the process has memory. Too many means it over-alternates, which usually means it was constructed rather than observed. Expected runs depend only on the two counts, so the frequency question is answered separately.

At a glance

Formula shown
With n₁ of one symbol and n₂ of the other, a random arrangement has E[R] = 2n₁n₂/n + 1 runs and Var(R) = 2n₁n₂(2n₁n₂ − n) / (n²(n − 1)). The z statistic is (R − E[R])/√Var(R), optionally with a half-unit continuity correction toward the mean, and the p-value is two-sided because both too few and too many runs are departures from randomness.
Scenario support
Checking a random number generator, detecting drift or autocorrelation in a measurement series, testing whether a sequence of wins and losses is streaky, quality control on a production line, and distinguishing a fabricated “random” sequence from a real one.
Educational estimate
Planning support from the values you enter — not professional advice.

Identical counts, opposite verdicts

The clearest demonstration of what this test does takes two sequences with the same contents.

Ten 1s then ten 0s: 2 runs. A random arrangement of ten and ten averages 11, so z = −3.9055 and p = 0.000094. The sequence is clustered.

Perfect alternation of the same ten and ten: 20 runs. z = +3.9055, the same p-value, the opposite direction.

A frequency test cannot distinguish them at all. Both have exactly ten of each symbol, so any test of “is this a fair coin” passes both without comment. The information is entirely in the order.

Which is why the two tests answer different questions. A goodness-of-fit test asks whether the proportions are right; this asks whether the arrangement is. Both can pass while the other fails, and a sequence needs both to look random.

The tool draws every run boundary, so the statistic is countable by eye: mark each place the symbol changes, add one, and that is R.

People alternate too much, and the test catches it

Asked to write down a random sequence of heads and tails, almost nobody produces one. The failure has a consistent direction.

A long repeat feels wrong, so people switch more often than chance does. In a genuinely random sequence of 100 flips, a run of six or more is more likely than not; in a fabricated one it almost never appears.

The tool measures the detection rate. A fair sequence is flagged about 3% of the time. A switch probability of 0.6 — barely above fair, and about what people produce — is caught roughly half the time at n = 100, and 0.7 is caught almost always.

The counts stay perfectly plausible throughout. A fabricated sequence usually has close to 50 of each, which is exactly why a frequency check passes it and this one does not.

It is the same bias behind the gambler’s fallacy, seen from the production side rather than the prediction side: an expectation that short sequences should look like long ones.

Turning measurements into a sequence

The test is defined on two symbols, and most data is not binary. The classical route is to split at the median.

Each value becomes 1 if it is above the median and 0 if below. Values exactly at the median are dropped, which is the classical procedure and is why the reported n may be smaller than the number of measurements.

A drifting process collapses the run count. A series trending upward produces a long block below the median followed by a long block above it — two runs where many are expected, which is the process-control preset.

Autocorrelation shows up the same way. Any process where each observation resembles the one before it clusters above and below the median in blocks, and the test detects that without requiring a model of the correlation.

The split point is a choice, and the median is the conventional one because it balances the two counts and therefore maximises the test’s sensitivity. Splitting at a target value instead answers a different and often more useful question.

The continuity correction, and when it matters

The number of runs is a whole number and the normal distribution is continuous. The correction bridges that.

It moves the observed count half a unit toward the expected value before dividing, which makes the test slightly more conservative and the approximation closer to the true discrete distribution.

At small n it changes the answer. The tool offers both so the difference is visible, and the corrected version is the default because at the sample sizes this test is used on, the uncorrected one is noticeably liberal.

Software disagrees about it, which is the usual reason two implementations give different p-values on the same sequence. Reporting which you used costs three words.

Below about twenty values, neither is reliable. The exact distribution of R is computable by enumeration and is the correct reference there; the normal approximation is a convenience for longer sequences.

What it detects, and what it misses

The test is sensitive to one specific kind of departure, and blind to several others.

It catches clustering and over-alternation. Both are first-order dependence — each value depending on the one immediately before it — and that is the test’s whole domain.

It misses longer-period structure entirely. A sequence repeating every seven positions can have a perfectly ordinary run count. An autocorrelation plot at several lags sees that; this does not.

It ignores the run LENGTHS. One run of twenty and twenty runs of one give very different pictures with the same total, and the statistic uses only the count. The longest run is printed above for that reason, and it is not part of the test.

And it says nothing about the proportions. A sequence of 95 ones and 5 zeros can pass comfortably. Randomness needs both this test and a frequency check, and passing one is not passing the other.

Reporting a randomness test

Four things, and the second is the one that makes it reproducible.

Report R with both counts. “12 runs from 20 ones and 18 zeros” carries everything needed to recompute; a bare p-value carries none of it.

Say whether the continuity correction was applied. It changes the answer at the sample sizes this test is used on, and implementations disagree by default.

Say how a numeric series was binarised. A median split and a split at a target value answer different questions, and the number of values dropped at the cut belongs in the report.

And name the direction. “Significantly non-random” is much less useful than “too few runs — the series is clustered”, which points at a cause.

Sources and methodology

References for the runs test and sequence randomness.

Method. Runs are counted by adjacent changes and the moments are the exact closed forms, verified against a hand computation on a small case. The demonstration that the test reads order alone is asserted numerically: the clustered and alternating twenty-value sequences have identical counts and z statistics of −3.9055 and +3.9055 that sum to zero to machine precision. The over-alternation detection rates are measured at 800 replications per switch probability, confirming a fair sequence is flagged under 7% of the time while a switch rate of 0.7 is caught over 90% — and that the mean run count rises monotonically with the switch rate. The continuity correction is verified to pull z toward zero. That engine is verified on every change against 69 assertions. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

Goodness of FitChi-square with per-cell contributions and standardised residuals, plus a measured answer to the “expected at least 5” rule — below the floor the test is CONSERVATIVE (3.27% at 2 per cell), not liberal.
Friedman TestRanks within each block and prints the rank matrix beside the raw values: three blocks of [1,2,3] plus one of [1000,2000,3000] give Kendall's W of exactly 1, because only the order is read.
Moving AverageSimple, exponential, weighted and centred moving averages with the lag each one carries — exactly (n−1)/2 periods for a simple average, which is also the reason α = 2/(n+1) is in every EMA formula.
Chi-SquareGoodness of fit and tests of independence with every expected count and per-cell contribution shown — because the validity condition is about expected counts, not observed ones, and most calculators hide them.
ProbabilityTwo events, repeated trials and Bayes, with the three usual errors handled — the dropped overlap in P(A or B), n×p instead of the complement, and the base rate that makes a 99% test 17% right.
Binomial DistributionExact binomial probabilities at any n — including thousands, where a factorial overflows — with the normal approximation beside them and its error measured, which is 0.6% at the centre and 261% in the tail.

More in Math, or browse all calculators.

Educational use disclaimer

An educational tool. The runs test detects first-order dependence only — it is blind to longer-period structure and ignores run lengths and proportions entirely, so passing it is evidence about one kind of randomness rather than about randomness in general.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (5 updates)

Published 12 September 2026

  1. Published the Wald–Wolfowitz runs test with every run boundary drawn, so the sequence structure the test reads is visible rather than summarised.
  2. Built the page around a pair no frequency test can distinguish: ten 1s followed by ten 0s gives z = -3.9055, and perfect alternation of the same twenty values gives +3.9055. Identical counts, mirror-image results.
  3. Added binarisation at the median for continuous sequences, which is how the test is applied to residuals and to time series in practice.
  4. Included the continuity correction and showed where it matters, which is exactly the short sequences where the normal approximation is weakest.
  5. Verified against the 69-assertion sequence suite, including the exact run-count distribution on small sequences where the normal approximation should not be trusted.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.