Date : Wed, 10 Apr 1985 16:42:38 GMT
From : Dave Sweeney <dms%dciem.uucp@BRL-TGR.ARPA>
Subject: Re: Random Numbers
Nick Cuccia writes:
>
>
> 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 *)
While A (= 2047) and M (= 524287) are mutually prime (HCF = 1), which
is all that is required for the algorithm, A is not a prime number:
2047 = 23 * 89
which will hopefully discourage 16-bit-machine users from using it
for M (which must be prime for the series to have full period).
Here at DCIEM we use an implementation of the generator described
on p. 464 of Knuth's vol. 2, with k = 55, j = 31. As no multiplications
or divisions are involved, it is reasonably fast.
--
Dave Sweeney, DCIEM
{allegra,ubc-vision,linus,ihnp4,uw-beaver,floyd}!utcsrgv!dciem!dms
or {allegra,ihnp4,linus,decvax}!utzoo!dciem!dms