You are on page 1of 9

Modeling and Simulation (408360)

Eng. Ghada Al-Mashaqbeh

RNG Performance Tests


For the following LCG apply all empirical tests as follows:
Zi = (17 Zi1 + 13) (mod 500), where Z0 = 1
1.
2.
3.
4.

chi-squares test: n = 50, k = 5, = 0.05


serial test: n = 60, d = 2, k =2, = 0.05
run test : use runs up, n = 50
correlation test: use lag 5, n = 50, = 0.05 .

Solution:
1) Chi-squared test:
a) generate the sample of random numbers: apply the LCG equation 50 times to find the following random
numbers shown in this table (numbers are stored column by column so U1 = 0.06, U2 = 0.046, U3 = 0.08,
and so on):
0.06
0.046
0.808
0.762
0.98
0.686
0.688
0.722
0.3
0.126

0.168
0.882
0.02
0.366
0.248
0.242
0.14
0.406
0.928
0.802

0.66
0.246
0.208
0.562
0.58
0.886
0.088
0.522
0.9
0.326

0.568
0.682
0.62
0.566
0.648
0.042
0.74
0.606
0.328
0.602

0.26
0.446
0.608
0.362
0.18
0.086
0.488
0.322
0.5
0.526

b) divide the interval [0,1) into 5 intervals and count the frequencies:
j
1
2
3
4
5

interval
[0, 0.2)
[0.2, 0.4)
[0.4, 0.6)
[0.6, 0.8)
[0.8, 1)

frequency
10
11
10
12
7

All frequencies > 5 fine no intervals merging


c) Compute the chi value
k k
n
= f j
n j =1
k

5 5
50
=
fj

50 j =1
5

Modeling and Simulation (408360)

(
= 0.1((10 10 )

Eng. Ghada Al-Mashaqbeh

= 0.1 ( f 1 10 ) + ( f 2 10 ) + ( f 3 10 ) + ( f 4 10 ) + ( f 5 10 )
2

+ (11 10 ) + (10 10 ) + (12 10 ) + (7 10 )


2

= 0.1(0 + 1 + 0 + 4 + 9)
= 1.4

d) Compare with critical value:


Degree of freedom = k-1 = 4
From table T.2 at page 717 we find:
2 k 1,1 = 2 4,0.95 = 9.488
1.4 < 9.488 this LCG passed the chi-squared test and so it is identical LCG.

2) Serial test:
a) Generate the sample of random numbers: apply the LCG equation 60 times to find the following random
numbers shown in this table (numbers are stored column by column so U1 = 0.06, U2 = 0.046, U3 = 0.08,
and so on):
0.06
0.046
0.808
0.762
0.98
0.686
0.688
0.722
0.3
0.126

0.168
0.882
0.02
0.366
0.248
0.242
0.14
0.406
0.928
0.802

0.66
0.246
0.208
0.562
0.58
0.886
0.088
0.522
0.9
0.326

0.568
0.682
0.62
0.566
0.648
0.042
0.74
0.606
0.328
0.602

0.26
0.446
0.608
0.362
0.18
0.086
0.488
0.322
0.5
0.526

0.968
0.482
0.22
0.766
0.048
0.842
0.34
0.806
0.728
0.402

b) Divide the sample into two-dimensional vectors where we will have 30 vectors as follows:
U1

[0.06, 0.046]

U11

[0.66, 0.246]

U21

[0.26, 0.446]

U2

[0.808, 0.762]

U12

[0.208, 0.562]

U22

[0.608, 0.362]

U3

[0.98, 0.686]

U13

[0.58, 0.886]

U23

[0.18, 0.086]

U4

[0.688, 0.722]

U14

[0.088, 0.522]

U24

[0.488, 0.322]

U5

[0.3, 0.126]

U15

[0.9, 0.326]

U25

[0.5, 0.526]

U6

[0.168, 0.882]

U16

[0.568, 0.682]

U26

[0.968, 0.482]

U7

[0.02, 0.366]

U17

[0.62, 0.566]

U27

[0.22, 0.766]

U8

[0.248, 0.242]

U18

[0.648, 0.042]

U28

[0.048, 0.842]

U9

[0.14, 0.406]

U19

[0.74, 0.606]

U29

[0.34, 0.806]

U10

[0.928, 0.802]

U20

[0.328, 0.602]

U30

[0.728, 0.402]

Modeling and Simulation (408360)

Eng. Ghada Al-Mashaqbeh

c) now let define the used equation:

kd
=
n
2

L f j1 j2L jd d
k
j1 =1 j2 =1
jd =1
k

22 2 2
30
f j1 j2 2

30 j1 =1 j2 =1
2

4 2 2
2
f j1 j2 7.5

30 j1 =1 j2 =1

Where:
j1 are the intervals on the first dimension.
j2 are the intervals on the second dimension.
j1
1
2

Interval on First
dimension
[0, 0.5)
[0.5, 1)

j2
1
2

Interval on Second
dimension
[0, 0.5)
[0.5, 1)

d) Compute vectors frequencies: Lets work some examples before stating the final frequencies.
U1 = [0.06, 0.046]
0.06 in the first interval [0, 0.5) of j1 j1 = 1
0.046 in the first interval [0, 0.5) of j2 j2 = 1
So it is counted for f 1,1
U2 = [0.808, 0.762]
0.808 in the second interval [0.5, 1) of j1 j1 = 2
0.762 in the second interval [0.5, 1) of j2 j2 = 2
So it is counted for f 2 , 2
U6 = [0.168, 0.882]
0.168 in the first interval [0, 0.5) of j1 j1 = 1
0.882 in the second interval [0.5, 1) of j2 j2 = 2

So it is counted for f 1, 2
Final frequencies:
interval
f 1,1

frequency
8

f 1, 2

f 2,1

f 2, 2

Modeling and Simulation (408360)

Eng. Ghada Al-Mashaqbeh

d) Compute 2

4 2 2
=
f j j 7.5
30 j1 =1 j2 =1 1 2
2

((

) (

4 2
2
f j11 7.5 + f j1 2 7.5

30 j1 =1

))
2

(
(

4
( f11 7.5)2 + ( f12 7.5)2 + ( f 21 7.5)2 + ( f 22 7.5)2
30
4
(8 7.5)2 + (7 7.5)2 + (6 7.5)2 + (9 7.5)2
=
30
= 0.67

e) Compare with critical value


Degree of freedom = kd-1 = 3
From table T.2 at page 717 we find:
2 k d 1,1 = 2 3, 0.95 = 7.815
0.67 < 7.815 this LCG passed the serial test and so it is IID.

3) Runs Test
a) Generate the sample of random numbers: apply the LCG equation 50 times to find the following random
numbers shown in this table (numbers are stored column by column so U1 = 0.06, U2 = 0.046, U3 = 0.08,
and so on):
0.06
0.046
0.808
0.762
0.98
0.686
0.688
0.722
0.3
0.126

0.168
0.882
0.02
0.366
0.248
0.242
0.14
0.406
0.928
0.802

0.66
0.246
0.208
0.562
0.58
0.886
0.088
0.522
0.9
0.326

0.568
0.682
0.62
0.566
0.648
0.042
0.74
0.606
0.328
0.602

0.26
0.446
0.608
0.362
0.18
0.086
0.488
0.322
0.5
0.526

b) Divide the sample into runs up and compute their length:


Run up
0.06
0.046, 0.808
0.762, 0.98
0.686, 0.688, 0.722
0.3

Length
1
2
2
3
1

Modeling and Simulation (408360)

Eng. Ghada Al-Mashaqbeh

0.126, 0.168, 0.882


0.02, 0.366
0.248
0.242
0.14
0.406, 0.928
0.802
0.66
0.246
0.208, 0.562, 0.58, 0.886
0.088, 0.522, 0.9
0.326, 0.568, 0.682
0.62
0.566, 0.648
0.042, 0.74
0.606
0.328
0.602
0.26, 0.446, 0.608
0.362
0.18
0.086, 0.488
0.322, 0.5, 0.526, 0.968
0.482
0.22, 0.766
0.048, 0.842
0.34, 0.806
0.728
0.402

3
2
1
1
1
2
1
1
1
4
3
3
1
2
2
1
1
1
3
1
1
2
4
1
2
2
2
1
1

c) Compute the frequency of runs length


ri

Frequency

r1 frequency of runs of length 1


r2 frequency of runs of length 2
r3 frequency of runs of length 3

17
10
5

r4 frequency of runs of length 4


r5 frequency of runs of length 5

2
0

r6 frequency of runs of length >= 6

Modeling and Simulation (408360)

Eng. Ghada Al-Mashaqbeh

d) Compute R as follows:
R=

1
N

a (r
i =1 j =1

ij

nbi )(r j nb j )

From your textbook page 408 you find the values of constants a and b as follows:

N is the number of runs which is = 34 in our example.


R=
=

1
N

a (r nb )(r
6

i =1 j =1

ij

nb j )

1 6 ai1 (ri nbi )(r1 nb1 ) + ai 2 (ri nbi )(r2 nb2 ) + ai 3 (ri nbi )(r3 nb3 ) + ai 4 (ri nbi )(r4 nb4 )

34 i =1 + ai 5 (ri nbi )(r5 nb5 ) + ai 6 (ri nbi )(r6 nb6 )

a11 (r1 nb1 )(r1 nb1 ) + a12 (r1 nb1 )(r2 nb2 ) + a13 (r1 nb1 )(r3 nb3 ) + a14 (r1 nb1 )(r4 nb4 )

+ a15 (r1 nb1 )(r5 nb5 ) + a16 (r1 nb1 )(r6 nb6 )
+ a (r nb )(r nb ) + a (r nb )(r nb ) + a (r nb )(r nb ) + a (r nb )(r nb )
2
1
1
22 2
2
2
2
23 2
2
3
3
24 2
2
4
4
21 2

+ a25 (r2 nb2 )(r5 nb5 ) + a26 (r2 nb2 )(r6 nb6 )

+ a31 (r3 nb3 )(r1 nb1 ) + a32 (r3 nb3 )(r2 nb2 ) + a33 (r3 nb3 )(r3 nb3 ) + a34 (r3 nb3 )(r4 nb4 )

1 + a35 (r3 nb3 )(r5 nb5 ) + a36 (r3 nb3 )(r6 nb6 )
=

34 + a41 (r4 nb4 )(r1 nb1 ) + a42 (r4 nb4 )(r2 nb2 ) + a43 (r4 nb4 )(r3 nb3 ) + a44 (r4 nb4 )(r4 nb4 )

+ a (r nb )(r nb ) + a (r nb )(r nb )
4
5
5
46 4
4
6
6

45 4
+ a51 (r5 nb5 )(r1 nb1 ) + a52 (r5 nb5 )(r2 nb2 ) + a53 (r5 nb5 )(r3 nb3 ) + a54 (r5 nb5 )(r4 nb4 )

+ a55 (r5 nb5 )(r5 nb5 ) + a56 (r5 nb5 )(r6 nb6 )
+ a61 (r6 nb6 )(r1 nb1 ) + a62 (r6 nb6 )(r2 nb2 ) + a63 (r6 nb6 )(r3 nb3 ) + a64 (r6 nb6 )(r4 nb4 )

+ a65 (r6 nb6 )(r5 nb5 ) + a66 (r6 nb6 )(r6 nb6 )

Modeling and Simulation (408360)

Eng. Ghada Al-Mashaqbeh

11
1
5
1
1
1

4529.4(17 50 * )(17 50 * ) + 9044.9(17 50 * )(10 50 * ) + 13568(17 50 * )(5 50 *


120
6
24
6
6
6

1
19
1
29
1
1
) + 22615(17 50 * )(0 50 *
) + 27892(17 50 * )(0 50 *
)

+ 18091(17 50 * )(2 50 *
6
720
6
5040
6
840

1
5
11
5
5
5

+ 9044.9(10 50 * 24 )(17 50 * 6 ) + 18097(10 50 * 24 )(10 50 * 24 ) + 27139(10 50 * 24 )(5 50 * 120 )

+ 36187(10 50 * 5 )(2 50 * 19 ) + 45234(10 50 * 5 )(0 50 * 29 ) + 55789(10 50 * 5 )(0 50 * 1 )

840
24
5040
24
720
24

+ 13568(5 50 * 11 )(17 50 * 1 ) + 27139(5 50 * 11 )(10 50 * 5 ) + 40721(5 50 * 11 )(5 50 * 11 )


120
24
120
6
120
120

1
11
29
11
19
11
)
)(0 50 *
) + 83685(5 50 *
)(0 50 *
) + 67852(5 50 *
)(r4 50 *

+ 54281(5 50 *
1
840
120
5040
120
720
120

11
19
5
19
1
19
34
)
)(5 50 *
)(10 50 * ) + 54281(2 50 *
)(17 50 * ) + 36187(2 50 *

+ 18091(2 50 *
120
720
24
720
6
720

19
1
19
29
19
19

+ 72414(2 50 * 720 )(2 50 * 720 ) + 90470(2 50 * 720 )(0 50 * 5040 ) + 111580(2 50 * 720 )(0 50 * 840 )

+ 22615(0 50 * 29 )(17 50 * 1 ) + 45234(0 50 * 29 )(10 50 * 5 ) + 67852(0 50 * 29 )(5 50 * 11 )

120
5040
24
5040
6
5040

+ 90470(0 50 * 29 )(2 50 * 19 ) + 113262(0 50 * 29 )(0 50 * 29 ) + 139476(0 50 * 29 )(0 50 * 1 )

5040
5040
720
5040
840
5040

11
1
5
1
1
1

+ 27892(0 50 *
)
)(5 50 *
)(10 50 * ) + 83685(0 50 *
)(17 50 * ) + 55789(0 50 *
120
840
24
840
6
840

1
1
29
1
19
1
)
)(0 50 *
) + 172860(0 50 *
)(0 50 *
) + 139476(0 50 *
)(2 50 *
+ 111580(0 50 *
840
840
5040
840
720
840

= 13317.9

e) Compare with critical value as in chi-square test.


Degree of freedom = 6
From table T.2 at page 717 we find:
2 6,1 = 2 6, 0.95 = 12.592
13317.9 > 12.592 this LCG failed to pass the runs test and so it is not independent.

4) Correlation Test
a) Generate the sample of random numbers: apply the LCG equation 50 times to find the following random
numbers shown in this table (numbers are stored column by column so U1 = 0.06, U2 = 0.046, U3 = 0.08,
and so on):

Modeling and Simulation (408360)

0.06
0.046
0.808
0.762
0.98
0.686
0.688
0.722
0.3
0.126

0.168
0.882
0.02
0.366
0.248
0.242
0.14
0.406
0.928
0.802

Eng. Ghada Al-Mashaqbeh

0.66
0.246
0.208
0.562
0.58
0.886
0.088
0.522
0.9
0.326

0.568
0.682
0.62
0.566
0.648
0.042
0.74
0.606
0.328
0.602

0.26
0.446
0.608
0.362
0.18
0.086
0.488
0.322
0.5
0.526

b) Lets work with lag 5 (i.e. j = 5) and see whether this LCG pass the correlation test for lag 5.
First we will compute the following:
Aj =
A5 =

[ ]

Var j

Var [ 5 ]

But:

j =

12 h
U 1+ kjU 1+( k +1) j 3
h + 1 k =0

5 =

12 h
U 1+5kU 1+5( k +1) 3
h + 1 k =0

And

h = (n 1) / j 1
h = (50 1) / 5 1
h = 9.8 1
h = 9 1 = 8
Then

5 =

12 8
U 1+5kU 1+5( k +1) 3
9 k =0

12
(U 1U 6 + U 6U 11 + U 11U 16 + U 16U 21 + U 21U 26 + U 26U 31 + U 31U 36 + U 36U 41 + U 41U 46 ) 3
9
12 0.06 * 0.686 + 0.686 * 0.168 + 0.168 * 0.242 + 0.242 * 0.66 + 0.66 * 0.886 + 0.866 * 0.568 +
3
=
9 0.568 * 0.042 + 0.042 * 0.26 + 0.26 * 0.86

12
(1.502) 3
9
= 0.997
=

Modeling and Simulation (408360)

Eng. Ghada Al-Mashaqbeh

Then

Var [ 5 ] =

13h + 7 13 * 8 + 7
=
= 1.37
81
(h + 1) 2

Finally we get:

A5 =

Var [ 5 ]

0.997
1.37

= 0.852

c) Compare A j with the critical value z1 / 2 = z 0.975 = 1.96 which is found in Table T.1 at page 716.

0.852 < 1.96 the LCG has passed the correlation test for lag 5 and so it is independent at this lag.

You might also like