06 Random Number Generation
06 Random Number Generation
06 Random Number Generation
Random-Number Generation
• Goal:
G l ToT produce
d a sequence off numbers
b in
i [0,1]
[0 1] that
th t
simulates, or imitates, the ideal properties of random
numbers
u be s (RN).
( )
f(x)
⎧1, 0 ≤ x ≤ 1
f ( x) = ⎨
⎩0, otherwise
1 x
2
x 1 1 0 1
E ( R) = xdx =
0 ∫
2
0
=
2
PDF for random numbers
• There
Th might
i ht be
b dependence:
d d
• Autocorrelation between numbers
• Numbers successively higher or lower than adjacent numbers
• Several numbers above the mean followed by several
numbers below the mean
i Zi Ui Zi×Zi
0 7182 - 51581124
1 5811 0.5811 33767721
2 7677 0.7677 58936329
3 9363 0.9363 87665769
…
X i +1 = (aX
X i + c) modd m, i = 0,1,2,...
The
Th The
Th The
Th
multiplier increment modulus
Xi
Ri = , i = 1,2,...
m
• Note:
• Xi ∈ {0, 1, ..., m-1}
• Ri ∈ [0,
[0 (m
(m-1)/m]
1)/m]
• Maximum Density
• The values assumed by Ri, i=1,2,… leave no large gaps on [0,1]
• Problem:
P bl IInstead
t d off continuous,
ti each
h Ri is
i di
discrete
t
• Solution: a very large integer for modulus m
• Approximation appears to be of little consequence
• Maximum Period
• To achieve maximum density y and avoid cycling
y g
• Achieved by proper choice of a, c, m, and X0
• The LCG has full period if and only if the following three
conditions hold (Hull and Dobell, 1962):
1. The only positive integer that (exactly) divides both m and c
is 1
2 If q is a prime number that divides m,
2. m then q divides a-1
a1
3. If 4 divides m, then 4 divides a-1
• For m a p
power 2,, m=2b, and c≠0
≠
• Longest possible period P=m=2b is achieved
if c is relative prime to m and a=1+4k, where k is an integer
X i +1, j = (a j X i + c j ) mod m j
X, Y, Z ∈ {1,...,30000}
X = X ⋅171 mod 30269
Y = Y ⋅ 172 mod 30307
Z = Z ⋅ 170 mod 30323
⎛ X Y Z ⎞
R =⎜ + + ⎟ mod 1.0
⎝ 30269 30307 30323 ⎠
• A random-number stream:
• Refers to a starting seed taken from the sequence (X0, X1, …, XP).
• If the streams are b values apart, then stream i is defined by starting seed:
Si = X b ( i −1) i = 1,2, K, ⎣ Pb ⎦
• Older generators: b = 105
• Newer generators: b = 1037
• Types of tests:
• Theoretical tests: evaluate the choices of m, a, and c without actually
generating any numbers
• Empirical
E i i l ttests:
t applied
li d tto actual
t l sequences off numbers
b produced.
d d
• Our emphasis.
h Ri ≤ x
N b off Ri where
Number
S N ( x) =
N
• Step 2: Compute
⎧i ⎫
D + = max ⎨ − R( i ) ⎬
1≤i ≤ N N
⎩ ⎭
⎧ i − 1⎫
D − = max ⎨ R(i ) − ⎬
1≤i ≤ N
⎩ N ⎭
• Step 3: Compute D = max(D+, D-)
• Step 4: Get Dα for the
significance level α
• Step 5: If D ≤ Dα accept,
otherwise reject j H0
n
(O − E ) 2
χ 02 = ∑ i i
i =1 Ei
• Approximately the chi-square distribution with n-1 degrees of
freedom
• For the uniform distribution, Ei, the expected number in each class
is:
N
Ei = , where N is the total number of observations
n
(Oi − Ei ) 2
n
χ =∑
2
0 X20=11.2
i =1 Ei
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
• Hypothesis:
H 0 : ρ i ,m = 0, if numbers are independen
p t
H 1 : ρ i ,m ≠ 0, if numbers are dependent
1 ⎡M ⎤
ρˆ i , m = ⎢ ∑
M + 1 ⎣ k =0
Ri + km × Ri +(k +1 )m ⎥ − 0.25
⎦
13M + 7
σˆ ρi ,m =
12( M + 1)
• z0.025 = 1.96
• Since -1.96 ≤ Z0 = -1.516 ≤ 1.96, the hypothesis is not rejected.
• http://www.comscire.com
• Caution:
• Even with generators that have been used for years, some of which
still
till in
i use, are found
f d to
t be
b inadequate.
i d t
• This chapter provides only the basics
• Also, even if generated numbers pass all the tests, some underlying
pattern might have gone undetected.