random numbers & generation

18
Random Numbers Random Numbers & & Their Their Generation Generation Submitted By: Karandeep Singh C08323 C.S.E. , 6 TH Sem.

Upload: kanwar-sukhbir-singh

Post on 26-Nov-2014

121 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Random Numbers & Generation

Random Numbers Random Numbers

&&Their GenerationTheir Generation

Submitted By:Karandeep SinghC08323C.S.E. , 6TH Sem.

Page 2: Random Numbers & Generation

OverviewOverviewImportance of random number generationDesiderata for a random number generator (RNG)

Methods for generating random numbersMethods for testing random number generators

Additional considerationsSummary

C08323

Page 3: Random Numbers & Generation

Importance of Importance of Random Number Random Number

GenerationGenerationIn simulation, we need them to model stochastic variation (if not, why are we simulating?)

We really need pseudo-random numbers, not random numbers, so that: – We can verify and validate more easily– We can test system alternatives under equal conditions

C08323

Page 4: Random Numbers & Generation

Desiderata for a RNGDesiderata for a RNG1. It should generate independent

values faithfully mimicking U[0,1]2. The RNG should be fast3. The RNG should need little storage4. The RNG should be portable5. The RNG should have a long cycle6. The random variates should be

replicable and available “by stream”

C08323

Page 5: Random Numbers & Generation

The Mid-Square The Mid-Square MethodMethod

Start with a 4-digit number, the seed

Square it to obtain an 8-digit number, with zero fill on left if needed

Middle 4 digits of those 8 are next random number

Let’s try it with 7182 as seed C08323

Page 6: Random Numbers & Generation

The Fibonacci MethodThe Fibonacci MethodZi = (Zi-1 + Zi-2) mod mThis type of generator usually has a period exceeding m

At first, it was praised in the literature

Oops – consecutive output values satisfying the inequality Zi-2 <Zi<Zi-1 are impossible1

That inequality should be satisfied 1/6 of time

C08323

Page 7: Random Numbers & Generation

The Linear The Linear Congruential MethodCongruential Method

Xi+1 = (aXi + c) mod mX0 is the seed– a is the constant multiplier– c is the increment– m is the modulus

If c≠0, “mixed congruential method”

If c=0, “multiplicative congruential method”

C08323

Page 8: Random Numbers & Generation

Longest (Best) CycleLongest (Best) CycleTo obtain the longest possible cycle:

1.Set m = 2b (consider computer word size)

2.Set c ≠ 0 (mixed congruential method)

3.Ensure GCD(c,m) = 14.Ensure a ≡ 1 mod 4

C08323

Page 9: Random Numbers & Generation

What If Longer Cycle What If Longer Cycle Needed?Needed?

On most computers, these methods achieve a cycle of length ≈ 109

Work in the 1980s by Pierre L’Ecuyer, a world expert in RNGs, produced combined linear congruential generators with cycles of length ≈ 1018

His more recent work has produced generators with cycles of length ≈ 1057

C08323

Page 10: Random Numbers & Generation

Tausworthe Tausworthe GeneratorsGenerators

These generators operate directly with bits to form random numbers

Essentially independent of computer’s word size

Huge cycles (e.g., > 10156 achieved)

Empirical evidence for their superiority lacking

GPSS/H abandoned use of these, returning to LCGs to facilitate stream management

C08323

Page 11: Random Numbers & Generation

Tests for Random Tests for Random NumbersNumbers

1. Frequency test – are the numbers evenly sprinkled on [0,1]?

Procedures available:– Kolmogorov-Smirnov– Anderson-Darling– χ2

This is a test for uniformity; the next four tests examine independence

C08323

Page 12: Random Numbers & Generation

Tests for Random Tests for Random NumbersNumbers

2. Runs tests Runs up and runs down – there

should be neither too few nor too many

Runs above and below the mean – there should be neither too few nor too many

Lengths of runs – should be variable

C08323

Page 13: Random Numbers & Generation

Tests for Random Tests for Random NumbersNumbers

3. Tests for autocorrelation Various lags may be examined

(e.g., is every 5th number high [or low])?

If successive pairs (Ri, Ri+1) are plotted in the unit square, do they fall on lines?

If successive triplets (Ri, Ri+1, Ri+2) are plotted in the unit cube, do they fall on planes?

C08323

Page 14: Random Numbers & Generation

Tests for Random Tests for Random NumbersNumbers

4. Tests for gaps What are the intervals between

successive occurrences of the same digit?

These intervals should follow the negative binomial distribution

C08323

Page 15: Random Numbers & Generation

Tests for Random Tests for Random NumbersNumbers

5. The Poker test For example, in random

numbers containing 4 decimal digits, how often do the following appear? –– “no pair,” e.g., 0.3785– “one pair,” e.g., 0.2278, 0.2782, 0.2728,0.7822– “two pairs,” e.g., 0.2323, 0.3322, 0.2332– “three of a kind,” e.g., 0.2223, 0.2232, 0.2322– “four of a kind,” e.g., 0.2222

C08323

Page 16: Random Numbers & Generation

Distributions Other Distributions Other than U[0,1]than U[0,1]

Basic RNGs are U[0,1] To obtain other distributions

from U[0,1], use:1. Inverse Transform technique2. Direct Transformation (for

normal or lognormal)3. Convolution4. Acceptance-Rejection C08323

Page 17: Random Numbers & Generation

Antithetic VariatesAntithetic Variates Two RNGs are antithetic if

corresponding numbers (e.g., the 984th number from each RNG) add to 1. That is, if one random number is high, its counterpart is low, and vice versa.

Excellent for variance reduction among consecutive pairs of replications.

C08323

Page 18: Random Numbers & Generation

SummarySummary RNGs are a specialized field of

study within simulation research

Understanding the basic principles of RNGs, and knowing the method used by the RNG in the software you’re using, is far superior to blind trust in a “black box”

C08323