Random Number Test Suite

Comprehensive statistical testing for random number generator quality

Test Configuration

Select Tests

Help

About Statistical Testing

Statistical tests evaluate whether a sequence of numbers behaves like true random numbers. Each test examines different properties:

  • Uniformity: Are values evenly distributed?
  • Independence: Are consecutive values uncorrelated?
  • Unpredictability: Can patterns be detected?
Chi-Square Test

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

Kolmogorov-Smirnov (K-S) Test

Compares empirical distribution to uniform distribution.

Measures: Maximum deviation between distributions

Advantage: More sensitive than chi-square for small samples

Runs Test

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

Gap Test

Examines distances between occurrences of values in a specific range.

What it detects: Periodicities, non-randomness in spacing

Poker Test

Groups values into "hands" and checks if frequencies match expected probabilities.

Inspired by: Poker hand probabilities

What it detects: Dependence between consecutive values

Serial Correlation Test

Measures correlation between values at different lags.

What it detects: Linear dependence between values

Expected: Correlation ≈ 0 for all lags

Interpreting P-Values

The p-value represents the probability of observing results at least as extreme as yours, assuming randomness.

  • p > α (e.g., 0.05): PASS - No evidence against randomness
  • p ≤ α: FAIL - Evidence suggests non-randomness
  • Very high p (> 0.95): Suspiciously perfect - may indicate issues
Overall Quality Assessment

A good RNG should:

  • Pass most tests (allow ~5% failure due to chance)
  • Have p-values distributed uniformly across [0,1]
  • Show no systematic patterns across multiple test runs
  • Pass at different sample sizes

Warning: Passing these tests doesn't guarantee cryptographic security!

When to Use Each Algorithm
  • LCG: Educational purposes only (known weaknesses)
  • Mersenne Twister: Scientific computing, simulations
  • XorShift: Games, fast simulations
  • Mulberry32: Quick simulations, testing
  • Math.random(): Non-critical applications (implementation varies)

For cryptography: Use crypto.getRandomValues() instead!