Date : Sun, 07 Apr 1985 18:49:03 pst
From : Nick "Coosh" Cuccia <cuccia%ucbmiro@ucb-vax.ARPA>
Subject: Re: Random Numbers
Hello out there...
Hope you don't mind if I toss out my fav'rit ref on random
number generators (oops! Pseudo-...). Check out V. 2 of Knuth's
_Art of Computer Programming_ for generation and testing methods.
I usually use the linear congruential method:
x = ax mod m
i+1 i
--------------
m
which gives numbers in the range [0..1). x sub i is the initial
seed, x sub (i+1) the seed used for the next call. Note: the
constants a and m should be relatively prime. An example function
written in Pascal is as follows. Another note: if a and m are
relatively prime then the period of the series generated will be
m.
--Nick Cuccia
--Computer Science Division,
--Dept. of Electrical Engineering and Computer Science,
--University of California-Berkeley
--cuccia%ucbmiro@Berkeley,
--{...}!ucbvax!cuccia
--cut here----cut here----cut here----cut here----cut here----cut here--
function Random(var x: integer): real;
const
A = 2047; (* = 2^11 - 1, a prime number *)
M = 524287; (* = 2^19 - 1, a prime number *)
begin (* random *)
x := (A*x) mod M; (* finding new seed value *)
Random := x / M; (* finding next number in series *)
end; (* function random *)