5 Random Numbers

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.

Random Numbers: notes

Random Numbers and its properties

A random number is a value produced by a process whose outcome is unpredictable and, ideally, cannot be reliably reproduced. In simulation, each random number $R$ is treated as an independent sample from the continuous uniform distribution on $(0,1)$, with density $f(x)=1$ for $0<x<1$, mean $E(R)=1/2$, and variance $\mathrm{Var}(R)=1/12$. Two properties are required of a good random-number sequence: uniformity, meaning every value in $(0,1)$ is equally likely, so that dividing $(0,1)$ into $n$ equal sub-intervals should, over $N$ observations, place about $N/n$ observations in each one; and independence, meaning the value of one random number carries no information about the value of the next.

Pseudo Random Numbers

Computers do not generate true randomness; they generate pseudo-random numbers, produced by a deterministic mathematical formula but designed to look statistically indistinguishable from a truly random sequence. A pseudo-random generator is fast, deterministic, and its sequence can be reproduced exactly from the same seed, which is actually useful for simulation since it lets an experiment be repeated identically. A true-random generator instead extracts randomness from a physical phenomenon, is slower, non-deterministic, and its sequence cannot be reproduced. Simulation almost always uses pseudo-random numbers precisely because reproducibility is valuable for debugging and for comparing two designs under identical random conditions.

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 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

Index12345678910
Value0.230.450.670.120.890.340.560.780.190.41
Index11121314151617181920
Value0.630.080.850.290.510.730.160.940.370.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$:

kIndexValue
020.45
150.89
280.78
3110.63
4140.29
5170.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
00.450.890.4005
10.890.780.6942
20.780.630.4914
30.630.290.1827
40.290.160.0464
50.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).}}$$

Open this answer on its own page →

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]

The random numbers $Ri$ are assumed to be drawn from a continuous uniform distribution over $[0,1]$: $$f(x) = \begin{cases} 1 & 0 \le x \le 1 \ 0 & \text{otherwise} \end{cases}$$ - $E(R) = \dfrac{1}{2}$, $\text{Var}(R) = \dfrac{1}{12}$ - Every equal-length sub-interval of $(0,1)$ is equally like...

Open this answer on its own page →

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 answer

Two Main Properties of Random Numbers and Autocorrelation Test

Part 1: Two Main Properties

  1. 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}$.

  2. 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:

iRiRiR
10.12110.99210.68
20.01120.15220.49
30.23130.33230.05
40.28140.35240.43
50.89150.91250.95
60.31160.41260.58
70.64170.60270.19
80.28180.27280.36
90.83190.75290.69
100.93200.88300.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
00.230.640.1472
10.640.990.6336
20.990.910.9009
30.910.750.6825
40.750.050.0375
50.050.190.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.

Open this answer on its own page →

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]

Category Observed $Oi$ ------ All four digits different 525 Exactly one pair 419 Two pairs 47 Three of a kind 9 All four alike 7 Total 1000 - $N = 1000$ numbers, each 4 digits - Critical value: $\chi^2{0.05,,4} = 9.49$ (degrees of freedom = 4) --- The Poker Test checks the independence of a sequ...

Open this answer on its own page →

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]

True random numbers are drawn from genuinely unpredictable physical processes (radioactive decay, thermal/electronic noise, atmospheric noise). Properties: - Non-deterministic and non-reproducible - Each value independent of all others - Require a physical source (hardware), slower to generate Ps...

Open this answer on its own page →

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]

Basis Chi-Square Test Kolmogorov-Smirnov (KS) Test --------- Data type Suited to discrete / grouped (binned) data Suited to continuous data, used on raw values Grouping Requires grouping into class intervals No grouping needed Sample size Needs a large sample ($N \ge 50$ typical) Valid for small ...

Open this answer on its own page →

Random Variate Generation

2082 · 5 marks

Discuss the inverse transform technique and acceptance-rejection technique for random variate generation. [5]

--- The inverse transform method generates random variates by inverting the Cumulative Distribution Function (CDF) of the desired probability distribution. The technique can be utilized for any distribution when the CDF, F(x), is of a form that its inverse F⁻¹ can be computed easily (e.g., expone...

Open this answer on its own page →

2076 · 5 marks

Explain generation of non uniform random number generation using inverse method. [5]

The Inverse Transform Method is a technique for generating random variates (non-uniform random numbers) from any desired probability distribution by using uniformly distributed random numbers R ~ U(0,1) as input. The core idea is based on the fact that if X is a continuous random variable with CD...

Open this answer on its own page →

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]

--- The Mid Square Method is one of the earliest and simplest techniques for generating pseudo-random numbers. It was proposed by John von Neumann. 1. Start with an n-digit seed number (initial value) $X0$. 2. Square the seed to obtain a $2n$-digit number (pad with leading zeros if necessary). 3....

Open this answer on its own page →

2080 · 5 marks

Generate 10 random integers using Linear congruential method where $m=1000$, $a=19$, $c=6$ and $X_0=13$. [5]

Parameter Value ------------------ Modulus $m$ 1000 Multiplier $a$ 19 Increment $c$ 6 Seed $X0$ 13 Number of random integers required: 10 $$X{n+1} = (aXn + c) \bmod m = (19Xn + 6) \bmod 1000$$ Since $c \neq 0$, this is the mixed (linear) congruential method. --- $X1$:

Open this answer on its own page →

2079 · 5 marks

Generate ten 3 digit random integers and corresponding random variables using Multiplicative Congruential method where a =7, and X0= 22. [5]

  • Method: Multiplicative Congruential Generator (MCG), so $c = 0$ - Multiplier: $a = 7$ - Seed: $X0 = 22$ - Required: ten 3-digit random integers and corresponding random numbers - Modulus $m$: not given in the question Missing data note: The modulus $m$ is not specified. For 3-digit integers, a ...
Open this answer on its own page →

2078 · 5 marks

Use Multiplicative congruential method to generate a sequence of random numbers with X=7, a=11 m=16. [5]

Show solved answer

Multiplicative Congruential Method

Given

ParameterValue
$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$
07130.8125
113150.9375
21550.3125
3570.4375
4713(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.

Open this answer on its own page →

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]

Parameter Symbol Value -------------------------- Seed $X0$ 27 Multiplier $a$ (given as $n$) 17 Modulus $m$ 100 Increment $c$ 43 Mixed (Linear) Congruential Method, with $c \ne 0$: $$X{i+1} = (aXi + c) \bmod m = (17Xi + 43) \bmod 100$$ $$Ri = \frac{Xi}{m}$$ --- Iteration 1: $$X1 = (17 \times 27 +...

Open this answer on its own page →