Upcoming SlideShare
×

# Generate and test random numbers

5,140 views
4,950 views

Published on

2 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
5,140
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
151
0
Likes
2
Embeds 0
No embeds

No notes for slide

### Generate and test random numbers

1. 1. Generate and Test Random Numbers<br />Eng. MshariAlabdulkarim<br />
2. 2. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Random Number Generation<br />
3. 3. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Types of Random-number Generators:<br /><ul><li>Combined generators.
4. 4. Inversive Generators.</li></li></ul><li>Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />When to use Combined Generators :<br /><ul><li>In the simulation of a highly reliable systems, where we need to simulate a huge number of events to observe any error.
5. 5. In the simulation of a complex networks, where there are a huge number of users running lots of programs.</li></li></ul><li>Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Combined Linear CongruentialGenerators :<br /><ul><li>In 1988, L’Ecuyer suggested a new way to generate a sequence numbers with a very long period, and that by combining two or more congruential generators.
6. 6. If Wi,1, Wi,2,..., Wi,kare independent, discrete-valued random variables, and Wi,1 is uniformly distributed between 0 and m1 – 2, then:</li></ul> is also uniformly distributed between 0 and m1 – 2.<br />
7. 7. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Combined Linear Congruential Generators (Cont):<br /><ul><li>L’Ecuyer suggested to combined generator of the form:</li></ul>With:<br />The maximum possible period will be:<br />
8. 8. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Example:<br />Two generators “k = 2”, a1 = 40014, m1 = 2147483563, a2 = 40692, m2 = 2147483399.<br />Algorithm:<br />Choose two seeds, X1,0 from [1, 2147483562] and X2,0 from [1, 2147483398], Set j = 0.<br />Calculate the values from the two generators:<br /> Then calculate:<br />After that return:<br />Finally:<br /> j = j + 1, and then go back to step number 2.<br />
9. 9. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Example (Cont.):<br />Period:<br />
10. 10. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />InversiveCongruential Generator :<br /><ul><li>Invarsivecongruential generators are a type of nonlinear congruential pseudorandom number generator.
11. 11. The standard formula for an inversivecongruential generator is:</li></li></ul><li>Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Testing Random Number<br />
12. 12. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Types of Random-number Testors:<br /><ul><li>Kolmogorov-Smirnov Test.
13. 13. Runs Tests.</li></li></ul><li>Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Kolmogorov-Smirnov Test :<br /><ul><li>Developed by A. N. Kolmogorov and N. V. Smirnov.
14. 14. Designed for continuous distributions.
15. 15. Difference between the observed CDF (cumulative distribution function) Fo(x) and the expected cdf Fe(x) should be small.</li></ul>Observed<br />Expected<br />
16. 16. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Kolmogorov-Smirnov Test :<br />
17. 17. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Example:<br />
18. 18. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Example (Cont.):<br />
19. 19. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Example (Cont.):<br />
20. 20. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Example (Cont.):<br />
21. 21. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Run Tests (Runs up and runs down):<br /><ul><li>The runs test examines the arrangement of numbers in sequence to test the hypothesis of independence.
22. 22. A run is defined as a succession of similar events preceded and followed by different event.
23. 23. The length of the run is the number of events that occur in the run.
24. 24. There are two Concerns in a runs test:</li></ul>Number of runs.<br />Length of runs.<br />
25. 25. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Run Tests (Runs up and runs down):<br /><ul><li>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.
26. 26. If α is the total number of runs in a truly random sequence, then:
27. 27. Mean:
28. 28. Variance:
29. 29. For N > 20, the distribution of “a” approximated by a normal distribution, N(ma , ).</li></ul>This approximation can be used to test the independence of numbers from a generator.<br />
30. 30. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Run Tests (Runs up and runs down):<br /><ul><li>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:
31. 31. Failure to reject the hypothesis of independence occurs when:</li></ul> Where α is the level of significance.<br />Fail to reject<br />
32. 32. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Example:<br /><ul><li>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.
33. 33. The sequence of runs up and down is as follows:</li></ul>+ + + -+-+- - - + + -+- - +-+- - +- - +-+ + - - + + -+- - + + -<br />
34. 34. Generate and Test Random Numbers<br />Generate and Test Random Numbers<br />Example (Cont.):<br /><ul><li>There are 26 runs in this sequence. With N=40 and a=26:
35. 35. Now, the critical value is Z0.025 = 1.96, so the independence of the numbers cannot be rejected on the basis of this test.</li>