Chapter 05 Generating Random Numbers
Chapter 05 Generating Random Numbers
Topics
Exercises
5.5) Caution
Caution
Caution
x 1
E ( R) = xdx = =
0 2 2
0
3 1 2
1 1 1 1
V ( R) = x dx − E (R )
1 x
= − = − =
2 2
MidSquare
Example:
X0 = 7182 (seed)
= 51581124
==> R1 = 0.5811
= (5811) 2 = 33767721
==> R2 = 0.7677
etc.
Xi
Ri = , i = 1,2,...
m
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}
Thus each Ri is discrete on I, instead of continuous on interval [0,1]
Maximum Density
→ Such that 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 (e.g., 231-1, 248)
Maximum Period
→ To achieve maximum density and avoid cycling.
→ Achieved by: proper choice of a, c, m, and X0.
Most digital computers use a binary representation of numbers
→ Speed and efficiency are aided by a modulus, m, to be (or
close to) a power of 2.
i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Xi 1 13 41 21 17 29 57 37 33 45 9 53 49 61 25 5 1
Xi 2 26 18 42 34 58 50 10 2
Xi 3 39 59 63 51 23 43 47 35 7 27 31 19 55 11 15 3
Xi 4 52 36 20 4
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
Not a viable generator !! Density insufficient, period too short
Copyright ©2010 by K. Plantenberg
Restricted use only
5.3.3) Combined Linear Congruential
Generators :
With increased computing power, the complexity of
simulated systems is increasing, requiring longer
period generator.
• Examples: 1) highly reliable system simulation
requiring hundreds of thousands of elementary
events to observe a single failure event;
• 2) A computer network with large number of nodes,
producing many packets
Approach: Combine two or more multiplicative
congruential generators in such a way to produce a
generator with good statistical properties
Xi
m , Xi 0
k
X i = (−1) X i , j mod m1 − 1
j −1
Hence, Ri = 1
j =1 m −1
1 , Xi = 0
m1
Two categories:
• Testing for uniformity. The hypotheses are:
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:
H0: Ri ~ independently distributed
H1: Ri ~ independently distributed
– Failure to reject the null hypothesis, H0, means
that evidence of dependence has not been detected.
Copyright ©2010 by K. Plantenberg
Restricted use only
5.4) Tests for Random Numbers
Test of uniformity
Two different methods:
• Kolmogorov-Smirnov test
• Chi-square test
Both these tests measure the degree of agreement between the
distribution of a sample of generated random numbers and the
theoretical uniform distribution
Both tests are based on null hypothesis of no significant difference
between the sample distribution and the theoretical distribution
Test is based on the largest absolute deviation statistic between F(x) and
SN(x) over the range of the random variable:
D = max| F(x) - SN(x)|
The distribution of D is known and tabulated (A.8) as function of N
Steps:
1. Rank the data from smallest to largest. Let R(i) denote ith smallest
observation, so that R(1)R(2)…R(N)
2. Compute i i − 1
D + = max − R(i ) ; D − = max R(i ) −
1i N N
1i N
N
3. Compute D= max(D+, D-)
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
i =1 Ei Oi is the observed
# in the ith class
1 M
ρˆ im =
M + 1 k =0
Ri + km i +(k +1 )m − 0.25
R
13M + 7
σˆ ρim =
12(M + 1 )
Example: Test whether the 3rd, 8th, 13th, and so on, for the output on
Slide 37 are auto-correlated or not.
• Hence, = 0.05, i = 3, m = 5, N = 30, and M = 4. M is the
largest integer such that 3+(M+1)530.
Shortcoming:
The test is not very sensitive for small values of M, particularly
when the numbers being tested are on the low side.
Problem when “fishing” for autocorrelation by performing numerous
tests:
• If = 0.05, there is a probability of 0.05 of rejecting a true
hypothesis.
• If 10 independent sequences are examined,
– The probability of finding no significant
autocorrelation, by chance alone, is 0.9510 = 0.60.
– Hence, the probability of detecting significant
autocorrelation when it does not exist = 40%
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.