Skip to main content

4.3 Testing random distributions

Source: Ideas from Computational Physics (Landau, Páez, Bordeianu), §4.4. Rewritten in original wording. Continues 4.2b Decay labs. Labs: 4.3b Random-distribution test labs.

A computer’s “random” stream follows a definite rule, so successive values are correlated. That can poison a Monte Carlo that assumes independent draws. Habit: run a few uniformity / randomness checks — ideally alongside the simulation that depends on them.

Look first​

The cheapest test is to look. A uniform generator on [0,1)[0,1) should spit values that clearly sit in that interval, differ from each other, and show no cartoon pattern like 0.33330.3333 forever.

Sample from the chapter LCG (r ← (1103515245 r + 12345) % 2³¹, then r/231r/2^{31}), seed 11:

0.5138700.1757410.3086520.534534
0.9476280.1717360.7022310.226431
0.4947730.1247200.0838990.389647

Your eye already sees [0,1)[0,1) coverage and no short repeating motif. That is not a proof — only a smoke test.

Visual structure tests​

  1. rir_i versus ii (Fig. 4.2 style). Expect a cloud filling the strip 0≤r<10\le r<1 with jitter, not a smooth curve.
  2. Successive-pair scatter (ri,ri+1)(r_i,r_{i+1}) or (r2i,r2i+1)(r_{2i},r_{2i+1}) (Fig. 4.1 style). Random uniforms fill the unit square as a featureless cloud. A lattice or stripes ⇒ reject for serious work.

Moment test for uniformity​

Walk the sample-moment definition, the exact ∫01xk=1/(k+1)\int_0^1 x^k=1/(k+1), the lag product C(k)C(k), and its 1/41/4 prediction — pick the matching equation at each step.

Practical checklist: k=1,3,7k=1,3,7 and N=102,104,105N=10^2,10^4,10^5; confirm N∣⟨xk⟩−1/(k+1)∣\sqrt{N}|\langle x^k\rangle-1/(k+1)| stays order one.

Lag-product correlation C(k)C(k)​

Near-neighbor dependence shows up in the lag product from the walk above. Matching 1/41/4 with N∣C−1/4∣=O(1)\sqrt{N}|C-1/4|=O(1) supports independence at lag kk. Still plot the scatter: a bad LCG can pass crude averages while failing the eye test.

Quiz

RNG tests

1 / 4

For uniform[0,1] draws, ⟨x³⟩ should approach…

Pick an answer to see if you are right.

Next: 4.3b Random-distribution test labs — moment and C(k)C(k) drills on the chapter LCG.