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 should spit values that clearly sit in that interval, differ from each other, and show no cartoon pattern like forever.
Sample from the chapter LCG (r ← (1103515245 r + 12345) % 2³¹, then ), seed :
| 0.513870 | 0.175741 | 0.308652 | 0.534534 |
| 0.947628 | 0.171736 | 0.702231 | 0.226431 |
| 0.494773 | 0.124720 | 0.083899 | 0.389647 |
Your eye already sees coverage and no short repeating motif. That is not a proof — only a smoke test.
Visual structure tests
- versus (Fig. 4.2 style). Expect a cloud filling the strip with jitter, not a smooth curve.
- Successive-pair scatter or (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 , the lag product , and its prediction — pick the matching equation at each step.
Practical checklist: and ; confirm stays order one.
Lag-product correlation
Near-neighbor dependence shows up in the lag product from the walk above. Matching with supports independence at lag . Still plot the scatter: a bad LCG can pass crude averages while failing the eye test.
RNG tests
1 / 4For 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 drills on the chapter LCG.