generate and test random numbers

Download Generate and test random numbers

If you can't read please download the document

Upload: mshari-alabdulkarim

Post on 16-Apr-2017

5.982 views

Category:

Technology


1 download

TRANSCRIPT

Random Number Generation

Generate and Test Random NumbersEng. Mshari Alabdulkarim

Random Number Generation

Generate and Test Random Numbers

Generate and Test Random Numbers

Types of Random-number Generators:

Combined generators.

Inversive Generators.

Generate and Test Random Numbers

Generate and Test Random Numbers

When to use Combined Generators :

In the simulation of a highly reliable systems, where we need to simulate a huge number of events to observe any error.

In the simulation of a complex networks, where there are a huge number of users running lots of programs.

Generate and Test Random Numbers

Generate and Test Random Numbers

Combined Linear Congruential Generators :

In 1988, LEcuyer suggested a new way to generate a sequence numbers with a very long period, and that by combining two or more congruential generators.If Wi,1, Wi,2,..., Wi,k are independent, discrete-valued random variables, and Wi,1 is uniformly distributed between 0 and m1 2, then:

is also uniformly distributed between 0 and m1 2.

Generate and Test Random Numbers

Generate and Test Random Numbers

Combined Linear Congruential Generators (Cont):LEcuyer suggested to combined generator of the form:

With:

The maximum possible period will be:

Generate and Test Random Numbers

Generate and Test Random Numbers

Example:Two generators k = 2, a1 = 40014, m1 = 2147483563, a2 = 40692, m2 = 2147483399.Algorithm:

Choose two seeds, X1,0 from [1, 2147483562] and X2,0 from [1, 2147483398], Set j = 0.Calculate the values from the two generators:

Then calculate:

After that return:

Finally: j = j + 1, and then go back to step number 2.

Generate and Test Random Numbers

Generate and Test Random Numbers

Example (Cont.):Period:

Generate and Test Random Numbers

Generate and Test Random Numbers

Inversive Congruential Generator :

Invarsive congruential generators are a type of nonlinear congruential pseudorandom number generator.

The standard formula for an inversive congruential generator is:

Generate and Test Random Numbers

Generate and Test Random Numbers

Testing Random Number

Generate and Test Random Numbers

Generate and Test Random Numbers

Types of Random-number Testors:

Kolmogorov-Smirnov Test.

Runs Tests.

Generate and Test Random Numbers

Generate and Test Random Numbers

Kolmogorov-Smirnov Test :

Developed by A. N. Kolmogorov and N. V. Smirnov.Designed for continuous distributions.Difference between the observed CDF (cumulative distribution function) Fo(x) and the expected cdf Fe(x) should be small.

ObservedExpected

Generate and Test Random Numbers

Generate and Test Random Numbers

Kolmogorov-Smirnov Test :

Generate and Test Random Numbers

Generate and Test Random Numbers

Example:

Generate and Test Random Numbers

Generate and Test Random Numbers

Example (Cont.):

Generate and Test Random Numbers

Generate and Test Random Numbers

Example (Cont.):

Generate and Test Random Numbers

Generate and Test Random Numbers

Example (Cont.):

Generate and Test Random Numbers

Generate and Test Random Numbers

Run Tests (Runs up and runs down):

The runs test examines the arrangement of numbers in sequence to test the hypothesis of independence.

A run is defined as a succession of similar events preceded and followed by different event.

The length of the run is the number of events that occur in the run.

There are two Concerns in a runs test:Number of runs.Length of runs.

Generate and Test Random Numbers

Generate and Test Random Numbers

Run Tests (Runs up and runs down):

If N is the number of numbers in a sequence, the maximum number of runs is N-1, and the minimum number of runs is one.

If is the total number of runs in a truly random sequence, then:

Mean:

Variance:

For N > 20, the distribution of a approximated by a normal distribution, N(ma , ).This approximation can be used to test the independence of numbers from a generator.

Generate and Test Random Numbers

Generate and Test Random Numbers

Run Tests (Runs up and runs down):

The standardized normal test statistic is developed by subtracting the mean from the observed number of runs , and dividing by the standard deviation. That is, the test statistic is:

Failure to reject the hypothesis of independence occurs when:

Where is the level of significance.

Fail to reject

Generate and Test Random Numbers

Generate and Test Random Numbers

Example:

Based on runs up and runs down, determine whether the following sequence of 40 numbers is such that the hypothesis of independence can be rejected where a = 0.05.

The sequence of runs up and down is as follows: + + + - + - + - - - + + - + - - + - + - - + - - + - + + - - + + - + - - + + -0.410.680.890.940.740.910.550.620.360.270.190.720.750.080.540.020.010.360.160.280.180.010.950.690.180.470.230.320.820.530.310.420.730.040.830.450.130.570.630.29

Generate and Test Random Numbers

Generate and Test Random Numbers

Example (Cont.):

There are 26 runs in this sequence. With N=40 and a=26:

Now, the critical value is Z0.025 = 1.96, so the independence of the numbers cannot be rejected on the basis of this test.

Generate and Test Random Numbers

Generate and Test Random Numbers