Skip to main content

Random number properties and Gap test

Short answer

Random numbers must be uniform over [0,1) and independent, with good generators having long periods and reproducibility. The gap test checks independence by comparing observed gap frequencies with F(x)=1-(0.9)^(x+1); the example gives D=0.2645, below the critical value 0.391, so independence is accepted.

What are the properties of random numbers? Explain the steps of the Gap test algorithm with example.

Properties of random numbers

A sequence of random numbers R1, R2, ... used in simulation must have two main properties:

  1. Uniformity: each number is equally likely to fall anywhere in [0, 1). If the interval is divided into n equal classes, each should receive N/n of the N numbers.
  2. Independence: the value of a number must not depend on earlier numbers. No pattern, trend or correlation may exist.

Desirable properties of a good generator: long period (full cycle), fast and low memory use, reproducible (same seed gives the same sequence, which helps debugging), can be split into independent streams, and the numbers pass statistical tests.

Gap test

The gap test checks independence. A gap is the number of digits between two successive occurrences of the same digit. For a chosen digit (say 3), if the digits are random the probability that the gap length is x is

P(gap = x) = 0.1 x (0.9)^x

and the cumulative probability is F(x) = 1 - (0.9)^(x+1).

Steps (Kolmogorov-Smirnov version)

  1. Choose the digit (3) and write the sequence of random digits.
  2. Mark the positions where the digit occurs and find the gap lengths between successive occurrences.
  3. Make a frequency table of gaps and compute the cumulative relative frequency SN(x).
  4. Compute the theoretical F(x) = 1 - (0.9)^(x+1).
  5. Find D = max |SN(x) - F(x)|.
  6. Compare D with the critical value D(alpha) from the K-S table for N gaps. If D <= D(alpha), accept independence; otherwise reject.

Example: from a sequence of 120 random digits, digit 3 occurs at positions 7, 13, 18, 20, 35, 36, 41, 43, 45, 88, 90, 105. The gaps are 5, 4, 1, 14, 0, 4, 1, 1, 42, 1, 14 (N = 11 gaps).

Gap xFrequencySN(x)F(x) = 1 - 0.9^(x+1)abs(SN - F)
010.09090.10000.0091
140.45450.19000.2645
420.63640.40950.2269
510.72730.46860.2587
1420.90910.79410.1150
4211.00000.98920.0108

D = max difference = 0.2645.

Critical value for alpha = 0.05 and N = 11 is D(0.05) = 0.391 (K-S table). Since 0.2645 < 0.391, the hypothesis of independence is accepted: no evidence of dependence in the sequence.

(With very few gaps, the test has low power. In practice at least 50 or more gaps are used. Alternatively, the gap lengths can be grouped into classes and compared with expected frequencies by the chi-square test.)

✓ Answer checked by Claude Opus 5.5 (high effort)

All Simulation and Modeling chapter 6 questions →