06
06
Contents
• Properties of Random Numbers
• Pseudo-Random Numbers
• Generating Random Numbers
• Linear Congruential Method
• Combined Linear Congruential Method
• Tests for Random Numbers
• Real Random Numbers
Overview
• Discuss characteristics and
the generation of random
numbers.
• Subsequently, introduce
tests for randomness:
• Frequency test
• Autocorrelation test
Overview
• Historically
• Throw dices
• Deal out cards
• Draw numbered balls
• Use digits of π
• Mechanical devices (spinning disc, etc.)
• Electric circuits
• Electronic Random Number Indicator (ERNIE)
• Counting gamma rays
• In combination with a computer
• Hook up an electronic device to the computer
• Read-in a table of random numbers
Pseudo-Random Numbers
Pseudo-Random Numbers
• Approach: Arithmetically generation (calculation) of
random numbers
• “Pseudo”, because generating numbers using a known
method removes the potential for true randomness.
f(x)
⎧1, 0 ≤ x ≤ 1
f ( x) = ⎨
⎩0, otherwise
1 x
2
1 x 1 0 1
E ( R) = xdx =
∫ = PDF for random numbers
0 2 2
0
Pseudo-Random Numbers
• Problems when generating pseudo-random numbers
• The generated numbers might not be uniformly distributed
• The generated numbers might be discrete-valued instead of
continuous-valued
• The mean of the generated numbers might be too high or too
low
• The variance of the generated numbers might be too high or
too low
i Zi Ui Zi×Zi
0 7182 - 51581124
1 5811 0.5811 33767721
2 7677 0.7677 58936329
3 9363 0.9363 87665769
…
Midsquare method
• Problem: Generated i Zi Ui Zi×Zi
numbers tend to 0
0 7182 - 51581124
1 5811 0,5811 33767721
2 7677 0,7677 58936329
3 9363 0,9363 87665769
4 6657 0,6657 44315649
5 3156 0,3156 09960336
6 9603 0,9603 92217609
7 2176 0,2176 04734976
8 7349 0,7349 54007801
9 78 0,0078 00006084
10 60 0,006 00003600
11 36 0,0036 00001296
12 12 0,0012 00000144
13 1 0,0001 00000001
14 0 0 00000000
15 0 0 00000000
… random numbers should not be
generated with a method chosen at
random. Some theory should be
used.
Xi
Ri = , i = 1,2,...
m
• Note:
• Xi ∈ {0, 1, ..., m-1}
• Ri ∈ [0, (m-1)/m]
Linear Congruential Method: Example
• Use X0 = 27, a = 17, c = 43, and m = 100.
• The Xi and Ri values are:
• Maximum Density
• The values assumed by Ri, i=1,2,… leave no large gaps on [0,1]
• Problem: Instead of continuous, each Ri is discrete
• Solution: a very large integer for modulus m
• Approximation appears to be of little consequence
• Maximum Period
• To achieve maximum density and avoid cycling
• 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, then q divides a-1
3. If 4 divides m, then 4 divides a-1
Linear Congruential Method:
Proper choice of parameters
X i +1 = g ( X i , X i −1 ,…) mod m
• where g() is a function of previous Xi’s
• Xi ∈ [0, m-1], Ri = Xi /m
X i +1, j = (a j X i + c j ) mod m j
• has prime modulus mj, multiplier aj, and period mj -1
• produces integers Xi,j approx ~ Uniform on [0, mj – 1]
• Wi,j = Xi,j - 1 is approx ~ Uniform on integers on [0, mj - 2]
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:
• Types of tests:
• Theoretical tests: evaluate the choices of m, a, and c without actually
generating any numbers
• Empirical tests: applied to actual sequences of numbers produced.
• Our emphasis.
Number of Ri where Ri ≤ x
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 H0
n 2
(O − E )
χ 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
2 (Oi − Ei ) 2
n
χ =∑
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 independent
H1 : ρi ,m ≠ 0, if numbers are dependent
1 ⎡ M ⎤
ρˆ i ,m = ⎢ ∑ Ri + km × Ri +(k +1 )m ⎥ − 0.25
M + 1 ⎣ k =0 ⎦
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 in use, are found to be inadequate.
• This chapter provides only the basics
• Also, even if generated numbers pass all the tests, some underlying
pattern might have gone undetected.