23
Tests for Tests for Random Number Generators Random Number Generators Jin Ui Yim Jin Ui Yim Inseok Oh Inseok Oh Junghoon Yang Junghoon Yang

Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Embed Size (px)

Citation preview

Page 1: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Tests for Tests for Random Number GeneratorsRandom Number Generators

Jin Ui YimJin Ui Yim

Inseok OhInseok Oh

Junghoon YangJunghoon Yang

Page 2: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Desirable properties of random numbersDesirable properties of random numbers

UniformityUniformity IndependenceIndependence

Page 3: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Methods to test random numbersMethods to test random numbers

Frequency testFrequency test (Uniformity) (Uniformity)Uses the chi-square test to compareUses the chi-square test to comparethe distribution of the set of numbers the distribution of the set of numbers generated to a uniform distribution.generated to a uniform distribution.

Autocorrelation test Autocorrelation test (Independence)(Independence) Tests the correlation between numbers and Tests the correlation between numbers and compares the sample correlation to the compares the sample correlation to the expected correlation, zero.expected correlation, zero.

Page 4: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Frequency test (Chi-Square Method)Frequency test (Chi-Square Method)

OOii - the observed number in the - the observed number in the iith classth class

EEii - the expected number in the - the expected number in the iith classth class n - the number of classesn - the number of classes

n

i i

ii

E

EOX

1

22

0

)(

Page 5: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Frequency test (Chi-Square Method)Frequency test (Chi-Square Method)

For the uniform distribution, For the uniform distribution, EEii , the expected number in each class is given by for , the expected number in each class is given by for

equally spaced classes.equally spaced classes.

n

NEi

N - the total number of observationsN - the total number of observations n - the number of classesn - the number of classes

Page 6: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Generating random number source(1)Generating random number source(1)

double[] data = new double[100];

//This object generates random number between 0 and 1

Random randomGenerator = new Random();

for ( int n = 0; n < 100; n++ )

{

//Makes random number

x = randomGenerator.nextDouble();

data[n] = x;

}

Page 7: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Generated random numberGenerated random number

0.34 0.90 0.25 0.89 0.87 0.44 0.12 0.21 0.46 0.670.83 0.76 0.79 0.64 0.70 0.81 0.94 0.74 0.22 0.740.96 0.99 0.77 0.67 0.56 0.41 0.52 0.73 0.99 0.020.47 0.30 0.17 0.82 0.56 0.05 0.45 0.31 0.78 0.050.79 0.71 0.23 0.19 0.82 0.93 0.65 0.37 0.39 0.420.99 0.17 0.99 0.46 0.05 0.66 0.10 0.42 0.18 0.490.37 0.51 0.54 0.01 0.81 0.28 0.69 0.34 0.75 0.490.72 0.43 0.56 0.97 0.30 0.94 0.96 0.58 0.73 0.050.06 0.39 0.84 0.24 0.40 0.64 0.40 0.19 0.79 0.620.18 0.26 0.97 0.88 0.64 0.47 0.60 0.11 0.29 0.78

Page 8: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Chi-Square Test Source(1)Chi-Square Test Source(1)

Page 9: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Chi-Square Test Source(2)Chi-Square Test Source(2)

n

i i

ii

E

EOX

1

22

0

)(

Page 10: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Frequency testFrequency test

The chi-square test conducted with The chi-square test conducted with a=0.05a=0.05 to test to test for whether the randomly generated data are for whether the randomly generated data are uniformly distributed.uniformly distributed.

9.1629,05.0

20 XX

The null hypothesis of a uniform distribution is The null hypothesis of a uniform distribution is not rejected when the result of chi-square is not rejected when the result of chi-square is smaller than the tabulated value.smaller than the tabulated value.

Page 11: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Frequency testFrequency test

double resultOfChiSquareTest = ChiSquareTest( data );if( resultOfChiSquareTest < 16.9)

System.out.println("The null hypothesis of a uniform distribution is not rejected.");

elseSystem.out.println("The null hypothesis of a uniform

distribution is rejected.");

Page 12: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Autocorrelation UseAutocorrelation Use

Economy- Stock Market Economy- Stock Market

GISGIS

Architecture EngineeringArchitecture Engineering

Information Technology - CDMAInformation Technology - CDMA

Page 13: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Autocorrelation NotionAutocorrelation Notion

The notion is that The notion is that numbers on the numbers on the sequence might be sequence might be related.related.

We will select the We will select the number with same number with same distance.distance.

10

7

4

1

R

R

R

R3

Page 14: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

AutocorrelationAutocorrelation mm - - m is the lag, the space between the numbers being m is the lag, the space between the numbers being

tested.tested. ii - - i is the index, or the number in the sequence that i is the index, or the number in the sequence that

you start with.you start with. N - The number of numbers generated in a sequenceN - The number of numbers generated in a sequence .. M - M is the largest integer such thatM - M is the largest integer such that

im

imZ

ˆ

0

ˆ

Pim - the estimator that is Pim - the estimator that is approxomitely normal approxomitely normal

Qpim - the standard deviation Qpim - the standard deviation of the estimator of the estimator

Page 15: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

AutocorrelationAutocorrelationEquation-Schmidt and TaylorEquation-Schmidt and Taylor

25.01

1ˆ0

)1(

M

kmkikmiim RR

M

nmi

i

R

R

n = k+1 10

7

4

1

R

R

R

R

As n is changed

Assume i = 1

m = 3 nmki )1(

So, We can calculate the k value.

Page 16: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

AutocorrelationAutocorrelationEquation-Schmidt and TaylorEquation-Schmidt and Taylor

nmki )1(

mmink

minkm

severythingnmkmi

/)(

)0(

15

.15

3/)3150(

50,3,1::

k

xxxxxxk

k

nmilet

Page 17: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

AutocorrelationAutocorrelationEquation-Schmidt and TaylorEquation-Schmidt and Taylor

)1(12

713ˆ

M

Mim

Page 18: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Autocorrelation Accept / RejectAutocorrelation Accept / Reject

im

imZ

ˆ0

ˆ 2/z 2/z

ACCEPTReject Reject

Page 19: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Autocorrelation Test SourceAutocorrelation Test Source

nmki )1(

25.01

1ˆ0

)1(

M

kmkikmiim RR

M

)1(12

713ˆ

M

Mim

im

imZ

ˆ

0

ˆ

Page 20: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

Autocorrelation Test Source(2)Autocorrelation Test Source(2)

im

imZ

ˆ0

ˆ 2/z 2/z

Page 21: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

========== Frequency Tests(Chi-Square) ==================== Frequency Tests(Chi-Square) ========== a = 0.05,X^2_0.05.9 = 16.9a = 0.05,X^2_0.05.9 = 16.9 The result of Chi-Square : 4.4The result of Chi-Square : 4.4 The null hypothesis of a uniform distribution is not rejected.The null hypothesis of a uniform distribution is not rejected.

========== Tests for Autocorrelation ==================== Tests for Autocorrelation ========== m = 5,i = 2m = 5,i = 2 N = 50,M(i+(M+1)m <= N) = 8N = 50,M(i+(M+1)m <= N) = 8 a = 0.05,Za/2 = 1.96a = 0.05,Za/2 = 1.96 The result of AutoCorrelation : 0.6440408970482641The result of AutoCorrelation : 0.6440408970482641 The null hypothesis of aThe null hypothesis of ann autocorrelationautocorrelation is not rejected. is not rejected.

ResultResult0.214499703350287340.21449970335028734

0.140169066903496180.14016906690349618

0.16450305180886070.1645030518088607

0.86386879618418970.8638687961841897

0.29091161497456250.2909116149745625

0.085903848037549580.08590384803754958

0.95338287249172180.9533828724917218

0.99367537683774750.9936753768377475

0.73888143694698280.7388814369469828

0.80088232526830480.8008823252683048

0.050161156694949690.05016115669494969

0.37871198912811510.3787119891281151

0.47688740881960270.4768874088196027

0.341209132342707670.34120913234270767

0.020965815160914890.02096581516091489

0.8103991129963630.810399112996363

0.83527981696041460.8352798169604146

0.13412314942352610.1341231494235261

0.409013955364263440.40901395536426344

0.97391104477288120.9739110447728812

0.87137635367732950.8713763536773295

0.6452013288456510.645201328845651

0.270275524601708560.27027552460170856

0.92957964314607430.9295796431460743

…………………………………………......

Page 22: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

ReferencesReferences

Discrete Event System Simulation 4rd Discrete Event System Simulation 4rd editionedition

CH7.1, CH7.4CH7.1, CH7.4 http://www.unf.edu/~rita0001/research/indehttp://www.unf.edu/~rita0001/research/inde

x.htmlx.html((Frequency testFrequency test ) )

http://www.itl.nist.gov/div898/software/dathttp://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/freqtest.htmaplot/refman1/auxillar/freqtest.htm((Autocorrelation TestAutocorrelation Test ) )

Page 23: Tests for Random Number Generators Jin Ui Yim Inseok Oh Junghoon Yang

ReferencesReferences

www.math.comwww.math.com www.wordiq.comwww.wordiq.com www.jstor.org(durbim-watsonwww.jstor.org(durbim-watson test) test) http://210.125.93.11/economics/dteco.asp?vhttp://210.125.93.11/economics/dteco.asp?v

iew=1&word=iew=1&word=자기상관자기상관 (economic book)(economic book)

http://chejucyber.cheju.ac.kr/kanggc/em/chahttp://chejucyber.cheju.ac.kr/kanggc/em/chap5/chap5.hwpp5/chap5.hwp (Jeju university) (Jeju university)