Test - Random Numbers
Test - Random Numbers
Random Numbers 1
Test for Random Numbers
(cont.)
4. Gap test. Counts the number of digits that appear
between repetitions of a particular digit and then
uses the Kolmogorov-Smirnov test to compare
with the expected number of gaps.
5. Poker test. Treats numbers grouped together as a
poker hand. Then the hands obtained are
compared to what is expected using the chi-square
test.
Random Numbers 2
Test for Random Numbers
(cont.)
In testing for uniformity, the hypotheses are as
follows:
H0: Ri ~ U[0,1]
H1: Ri U[0,1]
The null hypothesis, H0, reads that the numbers are
distributed uniformly on the interval [0,1].
Random Numbers 3
Test for Random Numbers
(cont.)
In testing for independence, the hypotheses are as
follows;
H0: Ri ~ independently
H1: Ri independently
This null hypothesis, H0, reads that the numbers are
independent. Failure to reject the null hypothesis
means that no evidence of dependence has been
detected on the basis of this test. This does not imply
that further testing of the generator for independence
is unnecessary.
Random Numbers 4
Test for Random Numbers
(cont.)
Level of significance
= P(reject H0 | H0 true)
Frequently, is set to 0.01 or 0.05
(Hypothesis)
Actually True Actually False
Accept 1 -
(Type II error)
Reject 1 -
(Type I error)
Random Numbers 5
FREQUENCY TEST
• The Kolmogrov –Smirnov test. This test
compares the continuous cdf, F(x), of the
uniform distribution to the empirical cdf,
SN(x), of the sample of N observations
Kolmogrov-Smirnov
Table
STEPS:
1.Rank the data from the smallest to largest.
2.Compute
i
D max Ri
1i N N
i 1
D max Ri
1 i N
N
3. Compute D = max (D+ , D-)
4. Determine the critical value, Dα .
5. If the sample statistic D is greater than the
critical value, Dα,the null hypothesis that the
data are a sample from a uniform
distribution is rejected.
Example:
Suppose that the five numbers 0.44, 0,81,
0,14, 0.05, 0,93 were generated. Perform a
test for uniformity using Kologrov-Smirnov
test with a level of significance α of 0.05
R(i) 0.05 0.14 0.44 0.81 0,93
i 1 Ei
Random Numbers 16
RUNS TEST (cont.)
Random Numbers 17
RUNS TEST (Cont.)
Substituting for aanda ==>
Za = {a - [(2N-1)/3]} / {(16N-29)/90},
where Z ~ N(0,1)
Acceptance region for hypothesis of
independence -Z Z0 Z
/ 2 / 2
-Z / 2 Z / 2
Random Numbers 18
Example
Based on runs up an down, determine whether the
following sequence of 40 numbers is such that
the hypothesis of independence can be rejected
where α = 0.05
0.41 0.68 0.89 0.94 0.74 0.91 0.55 0.71 0.36 0.30
0.09 0.72 0.86 0.08 0.54 0.02 0.11 0.29 0.16 0.18
0.88 0.91 0.95 0.69 0.09 0.38 0.23 0.32 0.91 0.53
0.31 0.42 0.73 0.12 0.74 0.45 0.13 0.47 0.58 0.29
Runs Test(cont.)
The sequence of runs up and down is as follows:
+ + + + + + + + + + + + + + + + + + +
There are 26 runs in this sequence. With N=40 and a=26,
a= {2(40) - 1} / 3 = 26.33 and
2
a {16(40) - 29} / 90 = 6.79
=
Then,
Z0 = (26 - 26.33) /
Now, the critical value is Z0.025 = 1.96, so the
independence of the numbers cannot be rejected on the
basis of this test.
Random Numbers 20
Runs Test
i 1 E (Yi )
2
The critical value is 3.84 (The degrees of
0.05,1
freedom equals the number of class intervals
minus one). Since 0 is less than the
2
Random Numbers 39
GAP TEST (cont.)
We are interested in the frequency of gaps.
P(gap of 10) = P(not 3) P(not 3) P(3) ,
note: there are 10 terms of the type P(not 3)
= (0.9)10 (0.1)
The theoretical frequency distribution for randomly
ordered digit is given
x
by
(0.9)n = 1 - 0.9x+1
F(x) = 0.1n 0
Note: observed frequencies for all digits are
compared to the theoretical frequency using the
Kolmogorov-Smirnov test.
Random Numbers 40
GAP TEST(cont.)
(Example)
Based on the frequency with which gaps occur,
analyze the 110 digits above to test whether they are
independent. Use = 0.05. The number of gaps is
given by the number of digits minus 10, or 100. The
number of gaps associated with the various digits are
as follows:
Digit 0 1 2 3 4 5 6 7 8 9
# of Gaps 7 8 8 17 10 13 7 8 9 13
Random Numbers 41
GAP TEST (cont.)
Gap Test Example
Relative Cum. Relative
Gap Length Frequency Frequency Frequency F(x) |F(x) - S N(x)|
0-3 35 0.35 0.35 0.3439 0.0061
4-7 22 0.22 0.57 0.5695 0.0005
8-11 17 0.17 0.74 0.7176 0.0224
12-15 9 0.09 0.83 0.8147 0.0153
16-19 5 0.05 0.88 0.8784 0.0016
20-23 6 0.06 0.94 0.9202 0.0198
24-27 3 0.03 0.97 0.9497 0.0223
28-31 0 0.00 0.97 0.9657 0.0043
32-35 0 0.00 0.97 0.9775 0.0075
36-39 2 0.02 0.99 0.9852 0.0043
40-43 0 0.00 0.99 0.9903 0.0003
44-47 1 0.01 1.00 0.9936 0.0064
Random Numbers 42
GAP TEST(cont.)
The critical value of D is given by
D0.05 = 1.36 / 100 = 0.136
Since D = max |F(x) - SN(x)| = 0.0224 is less
than D0.05, do not reject the hypothesis of
independence on the basis of this test.
Random Numbers 43
POKER TEST
Poker Test - based on the frequency with which
certain digits are repeated.
Example:
0.255 0.577 0.331 0.414 0.828 0.909
Note: a pair of like digits appear in each number
generated.
Random Numbers 44
Test for Random Numbers
(cont.)
In 3-digit numbers, there are only 3 possibilities.
P(3 different digits) =
(2nd diff. from 1st) * P(3rd diff. from 1st & 2nd)
= (0.9) (0.8) = 0.72
P(3 like digits) =
(2nd digit same as 1st) P(3rd digit same as 1st)
= (0.1) (0.1) = 0.01
P(exactly one pair) = 1 - 0.72 - 0.01 = 0.27
Random Numbers 45
Test for Random Numbers
(cont.)
(Example)
A sequence of 1000 three-digit numbers has been
generated and an analysis indicates that 680 have
three different digits, 289 contain exactly one pair
of like digits, and 31 contain three like digits.
Based on the poker test, are these numbers
independent?
Let = 0.05.
The test is summarized in next table.
Random Numbers 46
Test for Random Numbers
(cont.)
Observed Expected (Oi - Ei)2
Combination, Frequency, Frequency, -----------
i Oi Ei Ei
Three different digits 680 720 2.24
Three like digits 31 10 44.10
Exactly one pair 289 270 1.33
1000 1000 47.65
Random Numbers 47