Simulation and Modeling · Unit 5 · 7 hrs
Random Numbers
Exam-focused notes for Random Numbers (Simulation and Modeling, CSC328): what the TU syllabus asks and how it has actually been tested, with 13 solved past questions from this unit.
Random Numbers in short
Every stochastic simulation, the Monte Carlo estimate of unit 2, the arrival processes of unit 2, the queues of unit 3, ultimately runs on a stream of numbers that behave as if they were drawn independently from a uniform distribution on $(0,1)$. This chapter covers how such streams are generated, how they are tested for the randomness they claim to have, and how they are converted into samples from any other distribution a model needs.
What this unit covers
- Random Numbers and its properties
- Pseudo Random Numbers
- Methods of generation of Random Number
- Tests for Randomness - Uniformity and independence
- Random Variate Generation
Tests for Randomness - Uniformity and independence
2082 · 10 marks
What are the properties of random numbers?
The sequence of numbers 0.23, 0.45, 0.67, 0.12, 0.89, 0.34, 0.56, 0.78, 0.19, 0.41, 0.63, 0.08, 0.85, 0.29, 0.51, 0.73, 0.16, 0.94, 0.37, 0.59 has been generated. Test for the independence among numbers in the sequence starting with index $i = 2$ and lag $m = 3$ using auto-correlation test. ($\alpha = 0.05$, $Z_{\alpha/2} = 1.96$)[10]
Show solved answerHide answer
Properties of Random Numbers and Auto-Correlation Test
Part 1: Properties of Random Numbers
Random numbers $R_i$ must satisfy two key properties:
1. Uniformity The numbers are uniformly distributed on $(0,1)$; every value is equally likely. The pdf is:
$$f(x) = \begin{cases} 1 & 0 \le x \le 1 \ 0 & \text{otherwise} \end{cases}$$
with $E(R) = \tfrac{1}{2}$ and $Var(R) = \tfrac{1}{12}$.
2. Independence The current value has no correlation with previous values; the probability of observing a value in a subinterval is independent of prior draws.
Part 2: Auto-Correlation Test
Given Data
| Index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| Value | 0.23 | 0.45 | 0.67 | 0.12 | 0.89 | 0.34 | 0.56 | 0.78 | 0.19 | 0.41 |
| Index | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
|---|---|---|---|---|---|---|---|---|---|---|
| Value | 0.63 | 0.08 | 0.85 | 0.29 | 0.51 | 0.73 | 0.16 | 0.94 | 0.37 | 0.59 |
- $i = 2$, $m = 3$, $N = 20$, $\alpha = 0.05$, $Z_{\alpha/2} = 1.96$
Step 1: Find M
$M$ is the largest integer such that $i + (M+1)m \le N$:
$$2 + (M+1)\cdot 3 \le 20 \Rightarrow (M+1)\cdot 3 \le 18 \Rightarrow M+1 \le 6 \Rightarrow M \le 5$$
$$\boxed{M = 5}$$
Step 2: Subsequence Values
Indices $2 + 3k$ for $k = 0,1,\dots,5$:
| k | Index | Value |
|---|---|---|
| 0 | 2 | 0.45 |
| 1 | 5 | 0.89 |
| 2 | 8 | 0.78 |
| 3 | 11 | 0.63 |
| 4 | 14 | 0.29 |
| 5 | 17 | 0.16 |
Step 3: Auto-Correlation Estimate
$$\hat{\rho}m = \frac{1}{M+1}\left[\sum{k=0}^{M} R_{i+km},R_{i+(k+1)m}\right] - 0.25$$
The summation runs $k = 0$ to $M$, giving $M+1 = 6$ products of consecutive pairs:
| k | $R_{i+km}$ | $R_{i+(k+1)m}$ | Product |
|---|---|---|---|
| 0 | 0.45 | 0.89 | 0.4005 |
| 1 | 0.89 | 0.78 | 0.6942 |
| 2 | 0.78 | 0.63 | 0.4914 |
| 3 | 0.63 | 0.29 | 0.1827 |
| 4 | 0.29 | 0.16 | 0.0464 |
| 5 | 0.16 | ? | - |
Note on convention: The standard Banks/Carson formula sums $k=0$ to $M$ using pairs $R_{i+km}\cdot R_{i+(k+1)m}$, where the last term needs $R_{i+(M+1)m} = R_{2+18} = R_{20} = 0.59$.
Including the $k=5$ term: $0.16 \times 0.59 = 0.0944$.
$$\sum_{k=0}^{5} = 0.4005 + 0.6942 + 0.4914 + 0.1827 + 0.0464 + 0.0944 = 1.9096$$
$$\hat{\rho}_m = \frac{1.9096}{5+1} - 0.25 = \frac{1.9096}{6} - 0.25 = 0.31827 - 0.25 = 0.06827$$
Step 4: Standard Deviation of the Estimate
$$\sigma_{\hat{\rho}_m} = \frac{\sqrt{13M + 7}}{12(M+1)} = \frac{\sqrt{13(5)+7}}{12(6)} = \frac{\sqrt{72}}{72} = \frac{8.4853}{72} = 0.11785$$
Step 5: Test Statistic
$$Z_0 = \frac{\hat{\rho}m}{\sigma{\hat{\rho}_m}} = \frac{0.06827}{0.11785} = 0.5793$$
Step 6: Decision
Since $|Z_0| = 0.5793 < Z_{\alpha/2} = 1.96$, we fail to reject the null hypothesis of independence.
$$\boxed{\text{The numbers are independent (no significant autocorrelation).}}$$
2081 · 10 marks
Explain the independence and uniformity property of random number. For the following sample of random numbers, perform test for independence using K-S test. ($D_{0.05,10} = 0.41$) 0.35, 0.77, 0.12, 0.33, 0.88, 0.45, 0.19, 0.25, 0.91, 0.54[10]
2080 · 10 marks
What are the two main properties of random numbers? Test whether the 3rd, 7th, 11th, and so on numbers in the sequence in the following random number sample are auto-correlated. ($Z_{\alpha}=0.05$ and $Z_{0.025}=1.96$)
0.12, 0.01, 0.23, 0.28, 0.89, 0.31, 0.64, 0.28, 0.83, 0.93, 0.99, 0.15, 0.33, 0.35, 0.91, 0.41, 0.60, 0.27, 0.75, 0.88, 0.68, 0.49, 0.05, 0.43, 0.95, 0.58, 0.19, 0.36, 0.69, 0.87, [10]
Show solved answerHide answer
Two Main Properties of Random Numbers and Autocorrelation Test
Part 1: Two Main Properties
-
Uniformity: The random numbers $R_i$ are uniformly distributed on $[0,1]$. Each value is an independent draw from a continuous uniform distribution with pdf $$f(x)=\begin{cases}1 & 0\le x\le 1\ 0 & \text{otherwise}\end{cases}$$ giving $E(R)=\tfrac12$ and $Var(R)=\tfrac{1}{12}$.
-
Independence: Successive random numbers are statistically independent; the current value has no correlation with previous ones.
Part 2: Autocorrelation Test
Given Data
30 numbers, 1-indexed:
| i | R | i | R | i | R |
|---|---|---|---|---|---|
| 1 | 0.12 | 11 | 0.99 | 21 | 0.68 |
| 2 | 0.01 | 12 | 0.15 | 22 | 0.49 |
| 3 | 0.23 | 13 | 0.33 | 23 | 0.05 |
| 4 | 0.28 | 14 | 0.35 | 24 | 0.43 |
| 5 | 0.89 | 15 | 0.91 | 25 | 0.95 |
| 6 | 0.31 | 16 | 0.41 | 26 | 0.58 |
| 7 | 0.64 | 17 | 0.60 | 27 | 0.19 |
| 8 | 0.28 | 18 | 0.27 | 28 | 0.36 |
| 9 | 0.83 | 19 | 0.75 | 29 | 0.69 |
| 10 | 0.93 | 20 | 0.88 | 30 | 0.87 |
Test: 3rd, 7th, 11th, ... → starting index $i=3$, lag $m=4$. $Z_{0.025}=1.96$, $\alpha=0.05$.
Step 1: Determine M
Standard formula (Banks/Carson): $M$ = largest integer such that $i + (M+1)m \le N$, with $N=30$.
$$3 + (M+1)\cdot 4 \le 30 \Rightarrow (M+1)\cdot4 \le 27 \Rightarrow M+1 \le 6.75 \Rightarrow M+1=6 \Rightarrow M=5$$
So we use indices $3, 7, 11, 15, 19, 23$: that is $M+1 = 6$ values forming $M+1 = 6$ terms... let me apply the standard autocorrelation formula precisely.
The autocorrelation estimator: $$\hat\rho_{im}=\frac{1}{M+1}\left[\sum_{k=0}^{M}R_{i+km},R_{i+(k+1)m}\right]-0.25$$
This requires indices up to $i+(M+1)m$. With $i=3,m=4$: $3+(M+1)4\le30\Rightarrow M+1\le6.75\Rightarrow M=5$.
Indices needed: $3,7,11,15,19,23,27$ (from $k=0$ to $M+1=6$).
Values: $R_3=0.23,\ R_7=0.64,\ R_{11}=0.99,\ R_{15}=0.91,\ R_{19}=0.75,\ R_{23}=0.05,\ R_{27}=0.19$
Step 2: Products $R_{i+km}R_{i+(k+1)m}$, k = 0..M (=0..5)
| k | $R_a$ | $R_b$ | product |
|---|---|---|---|
| 0 | 0.23 | 0.64 | 0.1472 |
| 1 | 0.64 | 0.99 | 0.6336 |
| 2 | 0.99 | 0.91 | 0.9009 |
| 3 | 0.91 | 0.75 | 0.6825 |
| 4 | 0.75 | 0.05 | 0.0375 |
| 5 | 0.05 | 0.19 | 0.0095 |
$$\sum = 2.4112$$
Step 3: Compute $\hat\rho$
$$\hat\rho=\frac{1}{M+1}(2.4112)-0.25=\frac{2.4112}{6}-0.25=0.40187-0.25=0.15187$$
Step 4: Standard deviation
$$\sigma_{\hat\rho}=\frac{\sqrt{13M+7}}{12(M+1)}=\frac{\sqrt{13(5)+7}}{12(6)}=\frac{\sqrt{72}}{72}=\frac{8.4853}{72}=0.11785$$
Step 5: Test statistic
$$Z_0=\frac{\hat\rho}{\sigma_{\hat\rho}}=\frac{0.15187}{0.11785}=1.289$$
Step 6: Decision
Critical value $Z_{0.025}=1.96$.
Since $|Z_0| = 1.289 < 1.96$, we fail to reject the null hypothesis of independence.
Conclusion: There is no significant autocorrelation among the 3rd, 7th, 11th, ... numbers. They can be considered independent.
Common mistake: using $M = 6$ pairs and dividing by $M-1 = 5$, and then applying $\sigma = \frac{\sqrt{13M+7}}{12M}$ with that wrong $M$. The Banks-Carson convention gives $M = 5$, $\hat\rho = 0.1519$, $\sigma = 0.1179$ and $Z_0 \approx 1.29$. The conclusion (not autocorrelated) is the same, but the intermediate values are not.
2079 · 10 marks
Define and develop a Poker test for four-digit random numbers. A sequence of 1,000 random numbers, each of four digits has been generated. The analysis of the numbers reveals that in 525 numbers all four digits are different, 419 contain exactly one pair of like digits, 47 contain two pairs, 9 have three digits of a kind and 7 contain all like digits. Use Poker test to determine whether these numbers are independent. (Critical value of chi-square for a = 0.05 and N = 4 is 9.49).[10]
2078 · 10 marks
Define true random numbers and pseudo random numbers with its properties. The sequence of numbers 0.64, 0.50, 0.25, 0.58, 0.72, 0.90 has been generated. Use KS Test with Da=0.050 => 0512 to determine if the hypothesis that they are uniformly distributed on interval [0, 1] can be rejected.[10]
2076 · 10 marks
Difference between chi-square test and KS test for uniformity. Use KS test to check for the uniformity for the input set of random numbers given below. 0.54, 0.73, 0.98, 0.11, 0.68, 0.45. Assume level of significance to be $D_{a=0.05} => 0.565$ [10]
Random Variate Generation
2082 · 5 marks
Discuss the inverse transform technique and acceptance-rejection technique for random variate generation. [5]
2076 · 5 marks
Explain generation of non uniform random number generation using inverse method. [5]
Methods of generation of Random Number
2082 · 5 marks
Write a short note on: a. Mid Square Method b. Digital Analog Simulation [2.5+2.5]
2080 · 5 marks
Generate 10 random integers using Linear congruential method where $m=1000$, $a=19$, $c=6$ and $X_0=13$. [5]
2079 · 5 marks
Generate ten 3 digit random integers and corresponding random variables using Multiplicative Congruential method where a =7, and X0= 22. [5]
2078 · 5 marks
Use Multiplicative congruential method to generate a sequence of random numbers with X=7, a=11 m=16. [5]
Show solved answerHide answer
Multiplicative Congruential Method
Given
| Parameter | Value |
|---|---|
| $X_0$ (seed) | 7 |
| $a$ (multiplier) | 11 |
| $m$ (modulus) | 16 |
| $c$ | 0 (multiplicative case) |
Solution
Recurrence: $X_{n+1} = (a \cdot X_n) \bmod m = (11 \cdot X_n) \bmod 16$
Iteration 1: $$X_1 = (11 \times 7) \bmod 16 = 77 \bmod 16 = 13 \quad (77 = 4\times16 + 13)$$ $$R_1 = \frac{13}{16} = 0.8125$$
Iteration 2: $$X_2 = (11 \times 13) \bmod 16 = 143 \bmod 16 = 15 \quad (143 = 8\times16 + 15)$$ $$R_2 = \frac{15}{16} = 0.9375$$
Iteration 3: $$X_3 = (11 \times 15) \bmod 16 = 165 \bmod 16 = 5 \quad (165 = 10\times16 + 5)$$ $$R_3 = \frac{5}{16} = 0.3125$$
Iteration 4: $$X_4 = (11 \times 5) \bmod 16 = 55 \bmod 16 = 7 \quad (55 = 3\times16 + 7)$$ $$R_4 = \frac{7}{16} = 0.4375$$
Iteration 5: $$X_5 = (11 \times 7) \bmod 16 = 77 \bmod 16 = 13$$
Since $X_5 = X_1 = 13$, the sequence repeats. Period = 4.
Summary Table
| $n$ | $X_n$ | $X_{n+1}=(11 X_n)\bmod16$ | $R = X_{n+1}/16$ |
|---|---|---|---|
| 0 | 7 | 13 | 0.8125 |
| 1 | 13 | 15 | 0.9375 |
| 2 | 15 | 5 | 0.3125 |
| 3 | 5 | 7 | 0.4375 |
| 4 | 7 | 13 | (repeats) |
Result
Sequence of integers: $13, 15, 5, 7, 13, \ldots$
Sequence of random numbers: $$R = {0.8125,\ 0.9375,\ 0.3125,\ 0.4375, \ldots}$$
The period is 4, short because $m = 16$ is small.
2076 · 5 marks
Use Mixed congruential method to generate a sequence of random numbers with $X_0 = 27$, $n = 17$, $m = 100$ and $c = 43$. [5]
Make Unit 5 stick
Practice CSC328 with flashcards & quizzes