Associated Topics || Dr. Math Home || Search Dr. Math

### Generating Random Numbers

```
Date: 02/24/2001 at 22:01:22
From: Rodolfo Sanchez
Subject: Random Numbers

Although this question pertains to a college-level course (I study
engineering in Mexico), I wanted to go ahead and submit it.

Would you know of any congruential models (I assume that is the
translation) for the generation of random numbers?

(modelo congruencial para la generacion de numeros aleatorios)

Thanks for your time.

Rodolfo
```

```
Date: 02/25/2001 at 15:50:41
From: Doctor Fenton
Subject: Re: Random Numbers

Hi Rodolfo,

Thanks for writing to Dr. Math. For questions like yours, I generally
turn to the book _Numerical Recipes_ by William Press, et al. It is
written in several versions for different programming languages, and I
have both the first edition in FORTRAN and the second edition in C.

The C version mentions the "minimal standard generator" of Lewis,
Goodman, and Miller which uses:

I(n+1) == a*I(n) mod m   (== indicates congruence)

with

m = 2^31 - 1 = 2147483647
a = 7^5 = 1103515245

Apparently, a = 48272 and a=69621 have also been used, and all three
seem to work well.

The Fortran version gives a whole table of choices for a, c and m in:

I(n+1) == a*I(n)+c mod m

such as m = 714025, a = 1366, and c = 150889.

They also describe how to combine or "shuffle" the output of several
generators to get longer streams.

The definitive reference is Donald Knuth's _The Art of Computer
Programming: Seminumerical Algorithms_ (Volume 2).

I would recommend that you look up one of these references, since it
is easy to go wrong and generate non-random numbers.

If you have further questions, please write again.

- Doctor Fenton, The Math Forum
http://mathforum.org/dr.math/
```
Associated Topics:
College Algorithms
High School Calculators, Computers

Search the Dr. Math Library:

 Find items containing (put spaces between keywords):   Click only once for faster results: [ Choose "whole words" when searching for a word like age.] all keywords, in any order at least one, that exact phrase parts of words whole words

Submit your own question to Dr. Math
Math Forum Home || Math Library || Quick Reference || Math Forum Search

Ask Dr. MathTM
© 1994- The Math Forum at NCTM. All rights reserved.
http://mathforum.org/dr.math/