# Lecture 23 - Log-normal, Cauchy Distributions (pdf), Random number generators

## Final Comments on the Normal Distribution

• Use it varying mean and standard deviation
• Make certain that you are in a range where something happens
• Generate variables by
1. Somebody else's code, but be sure that 'somebody else' is reliable
• Too often somebody else is 'I don't known anything about them except that they came up first on Google.
2. Average of repeated Bernouilli samples
3. Tabular method
• Remember that it generates negative values, no matter how big the mean is.
• 'Rejection' (check to see if its negative and, if so, sample again) is the most common strategy.
• Quality of approximation is not too important as long as it has finite mean and variance.

# Two Last Distributions

## Log-normal Distribution

Normal distribution generates negative values

• Too many for rejection if mean < 3 * standard deviation
• What then?

How do we change negative numbers to positive ones?

• We exponentiate them: if -inf < x < inf then 0 < y = e^x < inf
• x = log(y) so put log(y) in where x was
• log-normal distribution exp(-((log(y) - mean)^2) / 2 )
• only provides sensible probabilities for 0 < y < inf.

## Cauchy Distribution

Normal distributions are your friend because they converge very well

 std. dev. % in tail on one side 1 16% 2 2.6% 3 0.23% 4 0.065%
• Sums of normal random variable are normally distributed
• Products of normal random variables are distributed by a Bessel function
• well-behaved, sums go to normal distributions
• But quotients of normal random variables are trouble!
• Cauchy distributions, which are not well-behaved

PDF

• f(x) = (a/\pi) (1/(x^2 + a^2 ) )

## Page 481 in the text.

 Name Definition Example Inversion Find explicit inverse of CDF as a function Exponential Cauchy Composition PDF is sum of two or more PDFs. Choose one at random and generate from it Convolution Random variable is a sum. Binomial Normal Characterization Find some special trick Normal Rejection Sample on a larger domain and reject ones outside Uniform circle Tabular inversion Define CDF as an interpolation table Normal

# Pseudo-Random Number Generators

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
• Otherwise choosing good values is a black art
• 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 2010?

## 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

Look at runs of points outside interval

• P( run of 0 ) = p
• P( run of 1 ) = p(1-p)
• etc.

This should be a geometric distribution

## Donald Knuth Wrote the Book

177 very dense pages in Semi-Numerical Algorithms

• published in 1981
• Volume 2 of The Art of Computer Programming
• Stopped in the middle to write TeX

## The Truth about Random Number Generation

How good do they have to be?

Look carefully at how your simulation uses random numbers

• the parts of your program that populate the event set

What type of correlations are you likely to care about? For example,

• lightly loaded single queue/single server
• two types of events
• Common sequences