Comprehensive statistical testing for random number generator quality
Statistical tests evaluate whether a sequence of numbers behaves like true random numbers. Each test examines different properties:
Tests if values are uniformly distributed across bins.
Null Hypothesis: Values follow uniform distribution
Pass Criteria: p-value > α (typically 0.05)
What it detects: Bias toward certain values or ranges
Compares empirical distribution to uniform distribution.
Measures: Maximum deviation between distributions
Advantage: More sensitive than chi-square for small samples
Tests for independence by counting sequences above/below median.
What it detects: Serial correlation, trends, patterns
Example: Too many runs = alternating pattern, too few = clustering
Examines distances between occurrences of values in a specific range.
What it detects: Periodicities, non-randomness in spacing
Groups values into "hands" and checks if frequencies match expected probabilities.
Inspired by: Poker hand probabilities
What it detects: Dependence between consecutive values
Measures correlation between values at different lags.
What it detects: Linear dependence between values
Expected: Correlation ≈ 0 for all lags
The p-value represents the probability of observing results at least as extreme as yours, assuming randomness.
A good RNG should:
Warning: Passing these tests doesn't guarantee cryptographic security!
For cryptography: Use crypto.getRandomValues() instead!