PickRandom Logo

PickRandom

Science

How to Test If a Random Number Generator Is Truly Random

An introduction to statistical randomness testing — the NIST test suite, Diehard tests, and practical methods for verifying whether a sequence of numbers is truly random.

Quick Answer: Statistical randomness tests analyze a sequence of numbers and check whether they exhibit properties expected of truly random sequences. The industry standard is the NIST SP 800-22 test suite (15 tests). Passing all 15 NIST tests is required for any CSPRNG used in government and security applications.

What Statistical Tests for Randomness Check

  • Frequency (Monobit) Test: Are 0s and 1s approximately equal in number?
  • Block Frequency Test: Is each block of the sequence balanced?
  • Runs Test: Are there too many or too few runs (consecutive identical values)?
  • Longest Run Test: Is the longest run of 1s within expected limits?
  • Binary Matrix Rank Test: Are there the right number of linearly independent rows?
  • Spectral Test (DFT): Are there any periodic patterns in the sequence?
  • Approximate Entropy Test: Is the entropy consistent with randomness?
  • Cumulative Sums Test: Does the sequence show expected random walk behavior?

The NIST SP 800-22 Test Suite

The National Institute of Standards and Technology (NIST) publishes SP 800-22: A Statistical Test Suite for Random and Pseudorandom Number Generators for Cryptographic Applications. It contains 15 statistical tests. Any CSPRNG used in US government applications must pass this suite. Many commercial and open-source implementations are tested against NIST standards.

The Diehard and TestU01 Suites

The Diehard test battery (by George Marsaglia) was the classic comprehensive randomness test suite before NIST. TestU01 (by Pierre L'Ecuyer) is the most comprehensive modern test suite for PRNGs, containing hundreds of tests in its "Crush" and "BigCrush" batteries. The Mersenne Twister passes all tests in small batteries but fails some BigCrush tests — irrelevant for practical use but noted for completeness.

No Test Suite Can Prove True Randomness

Statistical tests can detect detectable non-randomness — but they cannot prove that a sequence is truly random. A perfect PRNG (like a high-quality CSPRNG) will pass all tests. The tests confirm statistical properties expected of random sequences, not that the generator is physically random.

Frequently Asked Questions

How do I test if a random number generator is truly random?

Apply a standardized test suite like NIST SP 800-22 or TestU01 BigCrush. These tests check statistical properties expected of random sequences. Passing does not guarantee true randomness, but failing definitively indicates non-randomness.

What is the NIST randomness test suite?

NIST SP 800-22 is a published set of 15 statistical tests for random number sequences. It is the US government standard for certifying CSPRNGs used in security applications. Any CSPRNG must pass this suite before deployment in federal systems.

Does PickRandom.online's random generator pass randomness tests?

Yes — the Web Crypto API CSPRNG underlying PickRandom.online meets NIST SP 800-22 standards. It is the same generator standard approved for HTTPS encryption key generation.