Statistics & probability

Wald–Wolfowitz runs test calculator for binary randomness

Test the ordering of a binary sequence using an exact runs distribution conditional on its observed zero and one counts.

Your numbers

Enter 2–200 zeros and ones separated by commas or spaces. Preserve the original sequence order.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

A run is a maximal consecutive block of the same category. The sequence 0,0,1,1,0 has three runs: one block of zeros, one of ones and a final zero block. This calculator tests whether the observed number of runs is unusually far from its conditional expectation when every ordering of the recorded category counts is equally likely. Both unusually few and unusually many runs can contribute to its declared two-sided p-value.

THE FORMULAE[R] = 1 + 2n₀n₁/(n₀+n₁); count equally likely binary placements conditional on n₀ and n₁.

A worked example

For 0,0,0,1,1,1 there are two observed runs. With three zeros and three ones, the expected run count is four. Of the twenty possible binary placements with those counts, two have two runs and two have six runs. Both extremes are at least two runs from the expectation, so this page’s two-sided conditional p-value is 4/20 = 0.2.

Good to know

Requires both categories and a total length from 2 through 200. The null is exchangeable binary ordering conditional on counts; it is not a complete test of every property of randomness. This is not the NIST SP800-22 large-bitstream runs implementation. If numerical measurements are categorized, threshold and tie handling must be chosen in advance. Sorted or rearranged input cannot diagnose the original ordering.

Conditional counts isolate the ordering question

Three zeros and three ones can form a clustered sequence or a nearly alternating sequence. A frequency-only calculation cannot distinguish them because their category totals agree. Conditioning on those totals makes every placement of the ones among the available positions the reference outcome. Exact integer combinatorial counts produce the probability of each attainable run count without relying on a normal approximation.

The two-sided rule here uses absolute distance from the expected run count. Other conventions may double a smaller one-sided tail and need not give the same result for a discrete, asymmetric distribution. The complete distribution table makes the chosen rule auditable. Report the rule with the statistic instead of assuming that every result labelled two-sided uses the same set of extreme outcomes.

Three zeros followed by three ones form two runs000111Run 1Run 2Observed 2; expected 4
The first block is 000 and the second 111. With three of each category, expected runs are four; the distance-based exact two-sided tail includes runs two and six, giving p = 0.2.

The expected value calculator summarizes a supplied probability distribution; the runs table here constructs an exact distribution from binary ordering counts.

An ordering diagnostic cannot certify a generator

Few runs can suggest clustering or persistence, while many runs can suggest excessive alternation. Those are specific ordering patterns, not an exhaustive description of dependence. A sequence can pass this test and still contain predictable structure, biased frequencies or other weaknesses. Cryptographic generator assessment requires a broader design and cannot be reduced to one short binary sample or one non-significant p-value.

Thresholding continuous measurements creates a new binary sequence whose interpretation depends on that threshold. Decide how ties are assigned and how missing observations are treated before testing. This calculator accepts explicit zeros and ones so that it never silently reclassifies your measurements. Do not sort values first: sorting can manufacture long runs even when the original acquisition order had no such pattern.

A few questions, answered

Why reject a sequence containing only ones?

With one category absent, there is no meaningful two-category ordering contrast. The reference conditional distribution is degenerate.

Must the counts of zeros and ones be equal?

No. The exact distribution conditions on the actual counts. Both categories must occur, but their totals can differ.

Find your calculator

Start typing to explore the library.