# CS457 - System Performance Evaluation - Winter 2008

1. Tutorial: MC4045, Monday March 10, 18.00 to 19.00

# Random Number Generators - Pseudo-random Numbers

Text: Chapters 26 & 27

What we want

1. Computationally efficient
2. Gives good sequences of numbers
• uniform
• independent
3. Long periods
4. 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

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

#### Gap test

1. Choose an interval between zero and one, of length p
2. Then P( U in interval ) = p
3. 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