Skip to main content

Gap test algorithm; formulate poker test

Short answer

Gap test: pick target, count gaps between hits, compute F(x)=1−(1−p)^(x+1), test with K‑S or χ². Poker test: group four‑digit numbers; probabilities: all different 0.504, one pair 0.432, two pair 0.027, three of a kind 0.036, four of a kind 0.001. Compute χ²=∑(Oi−Ei)²/Ei with df=4; example with N=1000 gave χ²=1.069 < 9.488, not reject.

Write an algorithm for gap test. Formulate 4-digit poker test with suitable data with example.

Algorithm for the gap test

The gap test checks independence by examining the gaps between successive occurrences of a chosen digit. For a single digit the chance of occurrence is p = 0.1 (for an interval [α, β), p = β − α). Gap length x has probability p(1 − p)^x and cdf F(x) = 1 − (1 − p)^(x+1).

  1. Choose the target digit or interval [α, β).
  2. Scan the sequence and note each position where the target occurs. The gap is the count of non-target numbers between two consecutive occurrences.
  3. Group the n gaps by length (0, 1, 2, ..., and a last class "x or more").
  4. Find the observed relative frequencies and the cumulative function SN(x).
  5. Compute the theoretical F(x) = 1 − (1 − p)^(x+1).
  6. Compute D = max|F(x) − SN(x)| (K-S) and compare it with Dα for n gaps. Alternatively use χ0² = Σ (Oi − Ei)²/Ei with Ei = n·p(1 − p)^x.
  7. If the statistic is greater than the critical value, reject independence; else accept.

Four-digit poker test

The poker test treats each group of four digits like a poker hand and compares the observed counts of each pattern with the expected counts, using the chi-square test. Each random number is taken to four decimal places (e.g. 0.5127 gives digits 5, 1, 2, 7).

Probabilities of the patterns

PatternProbability
All four different0.504
One pair0.432
Two pairs0.027
Three of a kind0.036
Four of a kind0.001

Probabilities are found by counting: all different = 10·9·8·7/10⁴ = 0.504; four alike = 10/10⁴ = 0.001; and so on. They sum to 1.

Steps: (1) Take N numbers and classify each into a pattern. (2) Expected count Ei = N × probability. (3) Compute χ0² = Σ (Oi − Ei)²/Ei. (4) Degrees of freedom = classes − 1 = 4. (5) Reject independence if χ0² > χ²α,4.

Example. Suppose N = 1000 four-digit numbers give these counts (data assumed for illustration):

PatternOiEi(Oi − Ei)²/Ei
All different5055040.002
One pair4254320.113
Two pairs32270.926
Three of a kind37360.028
Four of a kind110.000

χ0² = 1.069. With α = 0.05 and df = 4, the critical value is 9.488. Since 1.069 < 9.488, we do not reject H0, and the numbers are accepted as independent.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Simulation and Modeling chapter 6 questions →