Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!linus!philabs!cmcl2!seismo!brl-tgr!tgr!cuccia%ucbmiro@ucb-vax.ARPA From: cuccia%ucbmiro@ucb-vax.ARPA (NickCoosh Cuccia) Newsgroups: net.micro.cpm Subject: Re: Random Numbers Message-ID: <9787@brl-tgr.ARPA> Date: Sun, 7-Apr-85 21:50:19 EST Article-I.D.: brl-tgr.9787 Posted: Sun Apr 7 21:50:19 1985 Date-Received: Tue, 9-Apr-85 03:53:40 EST Sender: news@brl-tgr.ARPA Lines: 41 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 *)