Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Homework/Assignment 4

(Chapter 4: Random Numbers)

Full Name of submitter: Cao Thị Minh Anh Student ID:


IELSIU18002
Your Group number is: 2

Group members are:


Student ID Name
1 IELSIU18002 Cao Thị Minh Anh
2 IELSIU18003 Cao Đoàn Trúc Phương Anh
3 IELSIU18068 Trương Ngọc Huyền Linh
4 IELSIU18096 Lương Thanh Bảo Ngọc
5 IELSIU18254 Đinh Thị Hồng Vui
6 IELSIU17041 Lê Phạm Hồng Ân
7 IELSIU18092 Trần Thị Hoàng Ngân

Answers
Slide 6-10: Use the linear congruential method to generate a sequence of random numbers
with: X0 = 27, a = 17, c = 43, and m = 100.
We have: Ri = Xi/m
Xi+1 = (aXi + c) mod m, i = 0, 1, 2, …
X0 = 27
X1 = (aX0 + c) mod m = (17*27 + 43) mod 100 = 502 mod 100 = 2 => R 1 = 2/100 = 0.02
X2 = (aX1 + c) mod m = (17*2 + 43) mod 100 = 77 mod 100 = 77 => R 2 = 77/100 = 0.77
X3 = (aX2 + c) mod m = (17*77 + 43) mod 100 = 1352 mod 100 = 52 => R 3 = 52/100 =0.52
X4 = (aX3 + c) mod m = (17*52 + 43) mod 100 = 927 mod 100 = 27 => R 4 = 27/100 =0.27

Slide 11: For 32-bit computers, L'Ecuyer [1988] suggests combining k = 2 generators with
m1=2,147,483,563, a1 =40,014, m2 = 2,147,483,399 and a2 = 40,692.
Select seeds: X1,0 in the range [1, 2,147,483,562] for the 1st generator.

1
X2,0 in the range [1, 2,147,483,398] for the 2nd generator.
 Set j = 0.
For each individual generator: X1,j+1 = 40,014X1,j mod 2,147,483,563
X2.j+1 = 40,692X1,j mod 2,147,483,399
Set Xj+1 = (X1,j+1 – X2,j+1) mod 2,147,483,562
Return:

X j +1

{
R j+1= 2,147,483,563
2,147,483,562
, X j+1 >0

, X =0
2,147,483,563 j +1

 Set j = j+1.
For each individual generator: X1,j+2 = 40,014X1,j+1 mod 2,147,483,563
X2.j+2 = 40,692X1,j+1 mod 2,147,483,399
Set Xj+2 = (X1,j+2 – X2,j+2) mod 2,147,483,562
Return:

X j+2

{
R j+2= 2,147,483,563
2,147,483,562
, X j+2 >0

, X =0
2,147,483,563 j +2

 Maximum possible period = (m1 - 1)(m2 - 1)/2


= (2,147,483,563 – 1)(2,147,483,399 – 1)/2
= 2x1018
Slide 17: Kolmogorov-Smirnov Test
Example: Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. => N=5
 Testing for uniformity:
H0: Ri ~ U[0,1]
H1: Ri ~ U[0,1]

Step 1: Arrange R(i ) from smallest to largest

i 1 2 3 4 5

2
R(i ) 0.05 0.14 0.44 0.81 0.93
i 0.2 0.4 0.6 0.8 1
n
i−1 0 0.2 0.4 0.6 0.8
n
Step 2: Calculate D+, D-
i 0.15 0.26 0.16 Negative 0.07
-R
n (i )
i−1 0.05 Negative 0.04 0.21 0.13
R(i )-
n

D+ = max {i/N – R(i)} = 0.26


D- = max {R(i) - (i-1)/N} =0.21
Step 3: D = max(D+, D-) = max( 0.26,0.21)=0.26

Step 4: Looking for Dn , α in Kolmogorov-Smirnov table with n=5 and a = 0.05

We have: D 5,0.05 = 0.56327

 D5,0.05 > D (0.56327> 0.26)

Hence, H0 is not rejected. So, evidence of non-uniformity has not been detected.

3
4

You might also like