Loading the lesson...
In the print dialog, choose "Save as PDF" as the destination.
Modeling and Simulation - Lesson 3
Two generators that produce random numbers, and three tests that check them: Exercise 3 solved step by step.
[0, 1] with a linear congruential generatorPart 1
The two properties every test checks
| Property | Meaning | Test |
|---|---|---|
| Uniformity | Every part of [0, 1] gets its fair share | Kolmogorov-Smirnov, chi-square |
| Independence | A number tells nothing about the next ones | Autocorrelation |
Part 2
The multiplicative generator and the LCG
Z0 is the seed, the starting valuea is the multiplier, m is the modulusx mod m is the remainder of x ÷ m, so every Zi is from 0 to m - 1Question 1
| i | (11 × Z) mod 16 | Zi |
|---|---|---|
| 1 | 11 × 1 = 11 → 11 | 11 |
| 2 | 11 × 11 = 121 → 9 | 9 |
| 3 | 11 × 9 = 99 → 3 | 3 |
| 4 | 11 × 3 = 33 → 1 | 1 |
| 5 | 11 × 1 = 11 → 11 | 11 (cycling) |
Question 1
| i | (11 × Z) mod 16 | Zi |
|---|---|---|
| 1 | 11 × 2 = 22 → 6 | 6 |
| 2 | 11 × 6 = 66 → 2 | 2 |
| 3 | 11 × 2 = 22 → 6 | 6 (cycling) |
Question 1, part 1 of 3
| i | (2 × Z) mod 13 | Zi |
|---|---|---|
| 1 | 2 × 1 = 2 | 2 |
| 2 | 2 × 2 = 4 | 4 |
| 3 | 2 × 4 = 8 | 8 |
| 4 | 2 × 8 = 16 → 3 | 3 |
| 5 | 2 × 3 = 6 | 6 |
Question 1, part 2 of 3
| i | (2 × Z) mod 13 | Zi |
|---|---|---|
| 6 | 2 × 6 = 12 | 12 |
| 7 | 2 × 12 = 24 → 11 | 11 |
| 8 | 2 × 11 = 22 → 9 | 9 |
| 9 | 2 × 9 = 18 → 5 | 5 |
| 10 | 2 × 5 = 10 | 10 |
Question 1, part 3 of 3
| i | (2 × Z) mod 13 | Zi |
|---|---|---|
| 11 | 2 × 10 = 20 → 7 | 7 |
| 12 | 2 × 7 = 14 → 1 | 1 (cycling) |
Q1 (c)
Question 1
| i | (3 × Z) mod 13 | Zi |
|---|---|---|
| 1 | 3 × 2 = 6 | 6 |
| 2 | 3 × 6 = 18 → 5 | 5 |
| 3 | 3 × 5 = 15 → 2 | 2 (cycling) |
| Case | Z0, a, m | Period |
|---|---|---|
| (a) | 1, 11, 16 | 4 = m / 4 |
| (b) | 2, 11, 16 | 2 |
| (c) | 1, 2, 13 | 12 = m - 1 |
| (d) | 2, 3, 13 | 3 |
c is the increment, added before the remainderXi is an integer from 0 to m - 1m to get a random number in [0, 1]Question 2
| i | 8 × X + 47 | Xi | Ri |
|---|---|---|---|
| 1 | 216 + 47 = 263 | 63 | 0.63 |
| 2 | 504 + 47 = 551 | 51 | 0.51 |
| 3 | 408 + 47 = 455 | 55 | 0.55 |
Q2
Part 3
Kolmogorov-Smirnov and chi-square
| Test | Statistic | Table |
|---|---|---|
| Kolmogorov-Smirnov | D | KS critical values, by N and α |
| Chi-square | χ0² | Chi-square values, by degrees of freedom and α |
R(1) ≤ R(2) ≤ ... ≤ R(N)D+, the largest distance above the ideal lineD-, the largest distance below itD = max(D+, D-)Dα from the KS table: if D < Dα, H0 is not rejectedQuestion 3
Kolmogorov-Smirnov test with α = 0.05, N = 5
Question 3
| i | R(i) | i / N | i / N - R(i) |
|---|---|---|---|
| 1 | 0.11 | 0.20 | 0.09 |
| 2 | 0.54 | 0.40 | -0.14 |
| 3 | 0.68 | 0.60 | -0.08 |
| 4 | 0.73 | 0.80 | 0.07 |
| 5 | 0.98 | 1.00 | 0.02 |
Question 3
| i | R(i) | (i - 1) / N | R(i) - (i - 1) / N |
|---|---|---|---|
| 1 | 0.11 | 0.00 | 0.11 |
| 2 | 0.54 | 0.20 | 0.34 |
| 3 | 0.68 | 0.40 | 0.28 |
| 4 | 0.73 | 0.60 | 0.13 |
| 5 | 0.98 | 0.80 | 0.18 |
Question 3
[0, 1] into n equal class intervalsOi, the values that fall in interval iEi = N / nχ0², the sum of (Oi - Ei)² / Eiχ² at α and n - 1 degrees of freedom: if χ0² is smaller, H0 is not rejectedQuestion 4
N = 100 values, listed in full on the lesson pagen = 10 intervals: [0, 0.1], (0.1, 0.2], ... , (0.9, 1.0]Ei = 100 / 10 = 10 valuesQuestion 4
| Interval | Oi | Oi - Ei | (Oi - Ei)² / Ei |
|---|---|---|---|
| [0, 0.1] | 8 | -2 | 0.4 |
| (0.1, 0.2] | 8 | -2 | 0.4 |
| (0.2, 0.3] | 10 | 0 | 0 |
| (0.3, 0.4] | 9 | -1 | 0.1 |
| (0.4, 0.5] | 12 | 2 | 0.4 |
Question 4
| Interval | Oi | Oi - Ei | (Oi - Ei)² / Ei |
|---|---|---|---|
| (0.5, 0.6] | 8 | -2 | 0.4 |
| (0.6, 0.7] | 10 | 0 | 0 |
| (0.7, 0.8] | 14 | 4 | 1.6 |
| (0.8, 0.9] | 10 | 0 | 0 |
| (0.9, 1.0] | 11 | 1 | 0.1 |
Question 4
Q4
Part 4
The autocorrelation test
i: the position of the first tested numberm: the lag, the distance between two tested numbers (not the modulus)N: the number of values in the sequenceM: the largest integer that keeps the last tested number inside the sequenceα = 0.05, so α/2 = 0.0250.975 in the normal tablezα/2 = 1.96: the limits are -1.96 and 1.96Question 5
30 numbers, α = 0.05
i = 3m = 5N = 30Question 5
| Position | Value | Position | Value |
|---|---|---|---|
| R3 | 0.23 | R18 | 0.27 |
| R8 | 0.28 | R23 | 0.05 |
| R13 | 0.33 | R28 | 0.36 |
Question 5
| k | Pair | Product |
|---|---|---|
| 0 | 0.23 × 0.28 | 0.0644 |
| 1 | 0.28 × 0.33 | 0.0924 |
| 2 | 0.33 × 0.27 | 0.0891 |
| 3 | 0.27 × 0.05 | 0.0135 |
| 4 | 0.05 × 0.36 | 0.0180 |
Question 5
Part 5
and practice
Xi / mD+ uses i/N - R(i), D- uses R(i) - (i - 1)/Nn - 1 intervals, not N - 1 valuesH0 is not rejectedM is rounded down: M ≤ 4.4 gives M = 4Z0 = 3, a = 5, m = 16: values until it cycles, and the periodX0 = 7, a = 21, c = 13, m = 100: the first three numbers in [0, 1]α = 0.05: 0.44, 0.81, 0.14, 0.05, 0.93α = 0.05: counts 12, 7, 9, 13, 9 in 5 equal intervalsZi = (a Zi-1) mod m; seed, multiplier and modulus set the periodXi = (a Xi-1 + c) mod m, then Ri = Xi / mD+ and D-, compare D with Dα(Oi - Ei)² / Ei, compare with the table at n - 1 degrees of freedomM, compute Z0, compare with ±zα/2Mahmoud Abas|Random Numbers: Generation and Testing