Documente Academic
Documente Profesional
Documente Cultură
CSC 446/546
Agenda
1. Properties of Random Numbers
2. Generation of Pseudo-Random Numbers (PRN)
3. Techniques for Generating Random Numbers
4. Tests for Random Numbers
Fall 2011
5. Caution
CSC 446/546
f ( x)
0, otherwise
2
x
E ( R ) xdx
0
2
1
V ( R ) x dx E R
1
Fall 2011
CSC 446/546
3 1
1
2
0
1 1 1
3 4 12
Fall 2011
CSC 446/546
2. Generation of Pseudo-Random
Numbers (PRN) (1)
Pseudo, because generating numbers using a known
method removes the potential for true randomness.
If the method is known, the set of random numbers can be
replicated!!
Goal: To produce a sequence of numbers in [0,1] that
Fall 2011
CSC 446/546
2. Generation of Pseudo-Random
Numbers (PRN) (2)
Problems that occur in generation of pseudo-random
numbers (PRN)
Generated numbers might not be uniformly distributed
Generated numbers might be discrete-valued instead of
continuous-valued
Mean of the generated numbers might be too low or too
high
Variance of the generated numbers might be too low or too
high
Fall 2011
CSC 446/546
2. Generation of Pseudo-Random
Numbers (PRN) (3)
Departure from uniformity and independence for a
particular generation scheme can be tested.
Fall 2011
CSC 446/546
2. Generation of Pseudo-Random
Numbers (PRN) (4)
Important considerations in RN routines:
The routine should be fast. Individual computations are
inexpensive, but a simulation may require many millions of
random numbers
Portable to different computers ideally to different
programming languages. This ensures the program produces
same results
Have sufficiently long cycle. The cycle length, or period
represents the length of random number sequence before
previous numbers begin to repeat in an earlier order.
Replicable. Given the starting point, it should be possible to
generate the same set of random numbers, completely
independent of the system that is being simulated
Fall 2011
Fall 2011
CSC 446/546
The
increment
The
modulus
10
Fall 2011
Xi
Ri , i 1,2,...
m
CSC 446/546
11
R1 = 0.02;
R2 = 0.77;
Notice that the numbers generated assume values only from the set
I = {0,1/m,2/m,.., (m-1)/m} because each Xi is an integer in
the set {0,1,2,.,m-1}
Fall 2011
12
Fall 2011
CSC 446/546
13
Fall 2011
For m a prime number and c=0, the longest possible period is P=m1, which is achieved whenever the multiplier a has the property
that the smallest integer k such that ak-1 is divisible by m is
k=m-1
CSC 446/546
14
10
11
12
13
14
15
16
Xi
13
41
21
17
29
57
37
33
45
53
49
61
25
Xi
26
18
42
34
58
50
10
Xi
39
59
63
51
23
43
47
35
27
31
19
55
11
15
Xi
52
36
20
m=64, c=0; Maximal period P=m/4 = 16 is achieved by using odd seeds X0=1 and X0=3 (a=13
is of the form 5+8k with k=1)
With X0=1, the generated sequence {1,5,9,13,,53,57,61} has large gaps
Fall 2011
15
Fall 2011
CSC 446/546
16
31
Fall 2011
Note that the routine divides by m+1 instead of m. Effect is negligible for such
large values of m.
CSC 446/546
17
Fall 2011
18
Wi
W
j 1
i, j
mod m1 1
Fall 2011
19
Fall 2011
CSC 446/546
20
j 1
(
1
)
X i , j mod m1 1
j 1
Fall 2011
X i
Xi
m ,
Hence, Ri 1
m 1
1 ,
m1
Xi 0
Xi 0
The maximum
(mpossible
1)...(mfor
1) a
1 1)( m2 period
k such
generatorPis:
2 k 1
CSC 446/546
21
Fall 2011
, X j 1 0
2,147,483,
563
R j 1
2,147,483,562 , X j 1 0
2,147,483,563
Step 5:
Set j = j+1, go back to step 2.
Combined generator has period: (m1 1)(m2 1)/2 ~ 2 x 1018
CSC 446/546
22
Si X b ( i 1) for i 1,2, , P b
Fall 2011
CSC 446/546
23
Fall 2011
CSC 446/546
24
Fall 2011
CSC 446/546
25
H0: Ri ~ U[0,1]
H1: Ri ~ U[0,1] /
Failure to reject the null hypothesis, H0, means that
evidence of non-uniformity has not been detected.
Testing for independence. The hypotheses are:
Fall 2011
26
Fall 2011
CSC 446/546
27
Fall 2011
CSC 446/546
28
Fall 2011
CSC 446/546
29
F ( x ) x, 0 x 1
If the sample from the RN generator is R1, R2, , RN, then the
empirical cdf, SN(x) is:
S N ( x)
Fall 2011
CSC 446/546
30
Test is based on the largest absolute deviation statistic between F(x) and SN(x)
over the range of the random variable:
i 1
i
R i ; D max R i
1i N N
1 i N
N
D max
Fall 2011
4. Locate in Table A.8 the critical value D, for the specified significance
level and the sample size N
5. If the sample statistic D is greater than the critical value D, the null
hypothesis is rejected. If D D, conclude there is no difference
CSC 446/546
31
Step 2:
R(i)
0.05
0.14
0.44
0.81
0.93
i/N
0.20
0.40
0.60
0.80
1.00
i/N R(i)
0.15
0.26
0.16
0.07
R(i) (i-1)/N
0.05
0.04
0.21
0.13
Fall 2011
32
(Oi Ei )
Ei
i 1
n
02
Ei is the expected
# in the ith class
Oi is the observed
# in the ith class
Fall 2011
33
Fall 2011
Example 7.7: Use Chi-square test for the data shown below with
=0.05. The test uses n=10 intervals of equal length, namely [0,0.1),
[0.1,0.2), ., [0.9,1.0)
CSC 446/546
34
Fall 2011
The value of 02=3.4; The critical value from table A.6 is 0.05,92=16.9.
Therefore the null hypothesis is not rejected
CSC 446/546
35
Fall 2011
This may be a small sample size, but the notion is that numbers in
the sequence might be related
CSC 446/546
36
i (M 1 )m N
M is the largest integer such that
Hypothesis:
H 0 : im 0,
H1 : im 0,
Fall 2011
CSC 446/546
37
1
im
M 1
im
R
k 0
i km
Ri (k 1 )m 0.25
13M 7
12(M 1 )
Fall 2011
38
Fall 2011
CSC 446/546
39
4 1 (0.28)(0.05) (0.05)(0.36)
0.1945
13(4) 7
0.128
12( 4 1 )
0.1945
Z0
1.516
0.1280
Fall 2011
35
From Table A.3, z0.025 = 1.96. Hence, the hypothesis is not rejected.
CSC 446/546
40
Fall 2011
CSC 446/546
41
5. Caution
Caution:
Even with generators that have been used for years, some of
which still in use, are found to be inadequate.
This chapter provides only the basics
Fall 2011
CSC 446/546
42