On this page
A fair die or a computer's random function is supposed to produce numbers with no pattern. You cannot prove that, but you can test it: compare what the sequence does with what chance would do, and flag gaps too big to be luck.
Below we run three classic tests by hand on one sample: the first 100 decimal digits of π, as listed on Pi Day's million-digit page.
How does the chi-square test check digit frequencies?
If the digits are random, each of 0 to 9 should turn up about equally often. The chi-square statistic measures the gap: χ² = Σ (O − E)² / E, where O is the observed count and E the expected count in each bin, as defined in the NIST/SEMATECH e-Handbook of Statistical Methods.
Counting the 100 digits gives:
0: 8, 1: 8, 2: 12, 3: 11, 4: 10
5: 8, 6: 9, 7: 8, 8: 12, 9: 14
The expected count for each digit is 100 ÷ 10 = 10. The squared gaps are 4, 4, 4, 1, 0, 4, 1, 4, 4 and 16, which add to 42. Divide by 10 and χ² = 4.2.
With 10 bins, the degrees of freedom are 10 − 1 = 9. NIST's table of chi-square critical values gives 16.919 for 9 degrees of freedom at the 5% level. Our 4.2 is far below it: pass. For a die example, see the chi-square goodness-of-fit test.
What does the runs test catch that chi-square misses?
Shuffle the digits and χ² does not change. The runs test looks at order. Label each digit L (0 to 4) or H (5 to 9); a run is an unbroken streak of the same label. NIST's runs test page gives the expected number of runs as 2n₁n₂/(n₁ + n₂) + 1, with variance 2n₁n₂(2n₁n₂ − n₁ − n₂) / ((n₁ + n₂)²(n₁ + n₂ − 1)). The score is Z = (runs − expected) / standard deviation, and you reject randomness at the 5% level if Z is beyond ±1.96.
For π's 100 digits there are 51 H, 49 L and 54 runs. The expected number is 2 × 51 × 49 / 100 + 1 = 50.98, the variance is about 24.73, so the standard deviation is about 4.97. Then Z = (54 − 50.98) / 4.97 ≈ 0.61. Pass.
The too-perfect 0123456789 becomes LLLLLHHHHH ten times: 20 runs where about 51 are expected, so Z ≈ −6.2. A clear fail.
How does the serial test check pairs?
The serial test asks whether every pattern of two (or more) symbols appears about equally often. NIST's SP 800-22 test suite describes it as checking whether the overlapping patterns occur as often "as would be expected for a random sequence".
With 100 digits, full digit pairs do not work: 50 pairs over 100 possible pairs is 0.5 expected each, too few for the chi-square approximation (NIST e-Handbook). So we pair L/H labels: 50 non-overlapping pairs, 4 kinds, 12.5 expected of each. (NIST's version counts overlapping patterns with an adjusted statistic.)
π gives LL 11, LH 19, HL 8 and HH 12. Then χ² = (2.25 + 42.25 + 20.25 + 0.25) / 12.5 = 5.2. With 3 degrees of freedom the 5% cut-off in NIST's table is 7.815, so π passes again. The repeating sequence gives LL 20, LH 10, HL 0, HH 20 and χ² = 22: a fail.
Does passing randomness tests prove numbers are random?
No. Every digit of π is fixed by a formula, yet it passes. NIST ran its test suite on the first 1,000,000 binary digits of π, and every P-value it reported was at or above its 0.01 cut-off: 0.419 for the runs test, 0.143 for the serial test, and 0.0102 for the spectral test, only just (NIST SP 800-22 Rev. 1a, Appendix B).
Nobody has even proved π is normal (every digit block equally frequent in the long run); MathWorld's entry on normal numbers calls this unresolved.
NIST's own abstract puts it plainly: "no set of statistical tests can absolutely certify a generator as appropriate for usage in a particular application" (NIST SP 800-22). Computer generators such as the linear congruential generator are deterministic too.
A checklist for testing your own numbers
Choose your tests and level (say 5%) before you look at the data.
Check expected counts are not tiny; merge bins, as we merged digits into L and H.
Run tests that look at different things: frequency, runs and pairs.
Treat a fail as evidence and a pass as no evidence, never as proof.
For passwords, use a generator built for security; SP 800-22 says statistical testing cannot replace cryptanalysis.
Try it: roll a die 60 times and run all three tests. If chi-square or degrees of freedom feel shaky, the Fermi Concept Library gives each mathematics concept its own lesson, and the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer.



