18+ --:--:-- UTC
← The RNG pillar
RNG Pillar·Chapter 10

Anatomy of a test battery

A statistical test battery is not one test but a suite of them, each sensitive to a different kind of non-randomness. This chapter walks through what a battery contains — frequency, runs, a chi-square uniformity test, a spectral or linear-complexity test — how each pass-or-fail decision is made against a critical value, and the honest core: passing a battery is necessary but not sufficient. It bounds statistical weakness; it cannot prove cryptographic unpredictability, and a genuinely fair source will occasionally fail a single test by chance — which is exactly what a significance level means.

By verified 2026-09-21Current · 100%

When a laboratory says an RNG “passed the statistical tests,” it is not describing one measurement. It is describing a battery: a suite of separate tests run over a long stream of the generator’s output, each one built to notice a different way a sequence can fail to look random. This chapter opens that suite up. It sets out what a battery actually contains, walks through a handful of representative tests and what each is sensitive to, shows exactly how a single pass-or-fail decision is made, and — the honest core — is precise about what a clean run does and does not prove. It extends two earlier chapters: what RNG tests can and cannot prove and what a certificate asserts. Nothing here is a method; it is a map of how the testing works and where its guarantees stop.

What a battery actually is

A single statistical test asks one narrow question of a sequence — is this particular pattern present more or less than pure randomness would produce? No one test can ask every such question, because there is no end to them. NIST’s canonical test-suite document, SP 800-22, makes the point exactly: “There are an infinite number of possible statistical tests, each assessing the presence or absence of a ‘pattern’ which, if detected, would indicate that the sequence is nonrandom. Because there are so many tests for judging whether a sequence is random or not, no specific finite set of tests is deemed ‘complete.’” A battery is the practical response to that fact: a curated collection of tests, each sensitive to a different class of non-randomness, run together so that a weakness invisible to one is likely to be caught by another. SP 800-22 bundles fifteen; empirical libraries go much further. The TestU01 library of L’Ecuyer and Simard packages predefined batteries of increasing stringency — SmallCrush, Crush and BigCrush — and its published study applies those batteries to a wide range of widely used generators, documenting which of them fail and where. The lesson of that work is that respectable-looking generators can and do fail a sufficiently thorough battery: breadth is the whole idea.

A walk through representative tests

The value of a battery is that its members do not overlap. A few representative examples show how different their sensitivities are.

Frequency (monobit). The most basic test simply counts: over a long binary stream, are there about as many ones as zeros? A generator with a persistent lean toward one bit value fails here first, which is why NIST recommends the frequency test be applied before the others — a sequence that cannot pass it has little chance of passing anything more demanding.

Runs. Balance is not enough; the order has to look random too. A runs test counts uninterrupted stretches of the same value and asks whether there are too many or too few, and whether they run too long. It catches a sequence that has the right totals but clumps or alternates in a way pure chance would rarely produce — a structure the frequency test is blind to.

Chi-square goodness-of-fit (uniformity). When outputs fall into categories — the six faces of a die, the sixteen values of a nibble — a chi-square test asks whether the observed counts match the uniform expectation closely enough. The NIST/SEMATECH e-Handbook gives the statistic as the sum over categories of “(observed − expected)² / expected,” which grows as the observed spread drifts from the expected one. This is the test made concrete in the explorable below.

Spectral / linear-complexity. The subtlest weaknesses are structural: a hidden periodicity, or an output that a short linear rule can reproduce. A spectral test looks for periodic components in the stream; a linear-complexity test asks how long a linear-feedback recurrence would have to be to generate what was seen — a sequence that a short recurrence can reproduce is not truly complex, however well-balanced it looks. These are precisely the kinds of structure a weak linear generator betrays, and the reason a battery reaches past simple counting.

How a pass or fail is decided

Every test in a battery reduces its sequence to a single number — a test statistic — and compares it to a critical value drawn from the distribution that statistic would follow if the source were truly random. SP 800-22 states the mechanic plainly: “If the test statistic value exceeds the critical value, the null hypothesis for randomness is rejected.” The equivalent p-value formulation turns the same comparison into a probability and checks it against a significance level α: “If P-value ≥ α, then the null hypothesis is accepted; i.e., the sequence appears to be random. If P-value < α, then the null hypothesis is rejected… The parameter α denotes the probability of the Type I error. Typically, α is chosen in the range [0.001, 0.01].” The critical value is just the threshold that α picks out in the tail of the reference distribution. For a chi-square test of a six-sided die there are five degrees of freedom (six categories minus one), and the upper critical value at α = 0.05 is 11.070 — exceed it and the test flags.

The explorable makes one member of a battery — the chi-square uniformity test — concrete and honest. Roll a six-sided die N times, optionally tilt it away from fair, and watch the single pass-or-fail decision the test would make: the observed counts against the expected N/6, the statistic, its five degrees of freedom, the critical value, and the verdict.

Live · one test in a battery — chi-square on a die

A fair six-sided die should land on each face about N/6 times. This runs one battery test — Pearson’s chi-square goodness-of-fit test — against that expectation. Roll the die, optionally tilt it away from fair, and watch a single test decide PASS or FLAG. Each roll uses Math.random, so every resample is a fresh, independent sample.

expected 100/face123456
χ² statistic
Degrees of freedom
5
Critical value (α=0.05)
11.07
Verdict

Rolling… The rule is exactly the one a real battery uses: reject the “fair die” hypothesis only when the statistic exceeds the critical value (0.00 11.07). At df = 5 and α = 0.05 that threshold is 11.07.

Lesson 1 — a fair die still FLAGs sometimes, by design. Keep the tilt at 0% and press Resample a dozen times. Every so often a perfectly fair die FLAGs anyway — roughly α of the time, about 1 in 20 at α = 5%. That is not evidence of a loaded die; it is precisely what the significance level means. A single failed test is a probabilistic event, not a verdict — which is why a real source can occasionally fail one test in a battery and still be sound.

Lesson 2 — a real bias is caught reliably only once N is large enough. Add a small tilt and roll just 60 times: the test usually misses it — the wobble is drowned in ordinary sampling noise. Hold the same tilt and raise N to 6,000 or 60,000, and now it FLAGs almost every time. A test’s power to catch a given bias grows with the sample; passing at small N proves very little. Both lessons point the same way: passing this test is necessary but not sufficient — it bounds one kind of statistical weakness, it does not prove the source is fair, let alone unpredictable.

Two things become obvious as you play with it. Keep the die perfectly fair and resample: every so often it flags anyway — roughly one time in twenty at α = 0.05 — which is not a loaded die but the significance level doing exactly what it is defined to do. Then add a small tilt and roll only sixty times: the test usually misses it, because a faint bias is buried in ordinary sampling noise. Raise N to sixty thousand and the same tilt is caught almost every time. Those are the two honest lessons a single test teaches, and they are why a battery is read as a whole and over long streams rather than trusted one test at a time.

Why a fair source still fails sometimes

The false alarm you just saw is not a defect in the test; it is a property built into it. SP 800-22 defines the significance level as precisely that risk: “α is the probability that the test will indicate that the sequence is not random when it really is random. That is, a sequence appears to have non-random properties even when a ‘good’ generator produced the sequence.” Run enough independent tests over enough data and a handful of spurious flags is not just possible but expected. This is why a lab does not treat one failed test as condemning a generator: it re-tests, looks at the pattern of results across the whole battery, and distinguishes a chance rejection from a reproducible one. A single FLAG is a signal to investigate, never a proof of unfairness — the mirror image of the fact that a single PASS proves very little on its own.

Necessary, not sufficient

Here is the honest core, and it must not be softened. Passing a battery is necessary but not sufficient. A battery bounds statistical weakness — it establishes that the output does not visibly deviate from independent, uniform randomness against the tests applied — and that is genuinely valuable. What it cannot do is prove that the generator is unpredictable to an adversary who has studied its output, because that is a question of cryptanalysis, not statistics. SP 800-22 draws the line itself, in its abstract: “no set of statistical tests can absolutely certify a generator as appropriate for usage in a particular application, i.e., statistical testing cannot serve as a substitute for cryptanalysis.” A sequence can sail through every test in a battery and still be produced by a generator whose next output an informed observer can compute — the weak-generator explorable in the opening chapter produces output that would pass basic uniformity checks and is nonetheless fully predictable from a handful of samples.

So read a clean battery result for exactly what it is worth: strong evidence that the output has no gross statistical flaw, and no evidence at all about cryptographic strength. That second property comes from a different discipline — a cryptographically strong design, an unpredictable seed, protected internal state — and it is what a certificate actually vouches for on top of the statistics, and why statistical testing alone cannot settle predictability. The battery is the floor, not the ceiling: passing it is the price of admission, not the proof of a fair game.

Common questions

If a certified RNG passes the whole battery, does that prove it is unpredictable?

No — and being clear about this is the point of the chapter. A battery bounds statistical weakness: it checks that the output looks like independent, uniform randomness against a fixed set of tests. It does not and cannot establish that an adversary who has watched the output cannot predict what comes next, which is a question of cryptanalysis, not statistics. NIST SP 800-22 states the limit directly in its abstract: "no set of statistical tests can absolutely certify a generator as appropriate for usage in a particular application, i.e., statistical testing cannot serve as a substitute for cryptanalysis." Passing is necessary but not sufficient — what a certificate adds on top of the statistics is covered in the certification and testing-limits chapters.

Can a genuinely fair generator fail a test in the battery?

Yes, and it will, occasionally — that is what the significance level means, not a sign of a fault. Each test rejects the randomness hypothesis when its statistic exceeds a critical value, and the significance level α is set so that this happens a small fraction of the time even for perfect randomness. In NIST’s words, α "is the probability that the test will indicate that the sequence is not random when it really is random. That is, a sequence appears to have non-random properties even when a ‘good’ generator produced the sequence." At α = 0.01 that is roughly one sequence in a hundred. A single flagged test is a probabilistic event to be investigated, not a verdict.

Why use many different tests instead of one good one?

Because each test is sensitive to a different kind of non-randomness, and no finite collection catches every kind. A frequency test notices a lopsided balance of bits; a runs test notices streaks that are too long or too short; a chi-square test notices an uneven spread across outcomes; a spectral or linear-complexity test notices hidden periodic or linear structure. NIST puts it plainly: "There are an infinite number of possible statistical tests … Because there are so many tests for judging whether a sequence is random or not, no specific finite set of tests is deemed ‘complete.’" A battery is a broad net, deliberately assembled — not a single pass-mark.

Sources (4)

Education, not advice. This chapter explains how the random number generators behind casino games are built, tested and certified so you can judge the claims made about them honestly. It is not a system, and nothing here treats gambling as a way to make money — over enough play the mathematics favours the house. 18+.

End of the current pathBack to the RNG pillar