# CS457 - System Performance Evaluation - Winter 2008

### Questions and Comments

- Tutorial: MC4045, Monday March 10, 18.00 to 19.00

# Lecture 26

# Random Number Generators - Pseudo-random Numbers

Text: Chapters 26 & 27

What we want

- Computationally efficient
- Gives good sequences of numbers
- Long periods
- Reproduce previous sequences for debugging

## Linear Congruential Generators

X(n) = ( aX(n-1) + b ) mod m

- a, b, m are constants
- The quality of the sequence depends strongly on the values chosen
for a, b & m.
- Period is a divisor of m

- X(0) is the seed
- u(i) = X(i) / m has the correct range.

How to get a full period - all possible values appear before repeating.

- GCD( m, b ) = 1
- Every prime factor of m is a factor of a-1.
- If 4 divides m the 4 must divide a-1

Choose m = 2^k for efficiency.

- Is this really true in 2008?

## Testing Sequences of Random Numbers

#### Serial test

- Get adjacent pairs of numbers as points in a plane.
- Put them into bins: kxk.
- If sequence is uniform and random then P(point is in a given cell) =
1/k^2
- Use Kolmogorov test (or chi-square test) to check the distribution.

#### Gap test

- Choose an interval between zero and one, of length p
- Then P( U in interval ) = p
- Look at runs of points outside interval
- P( run of 0 ) = p
- P( run of 1 ) = p(1-p)
- etc.

This is a geometric distribution

# Relationship between Poisson and Exponential Distributions

Please see this pdf.

Return to: