martens@dinghy.cis.ohio-state.edu (Jeff Martens) (06/01/90)
In article <1932@mindlink.UUCP> a275@mindlink.UUCP (Travers Naran) writes: >Does anyone have a good random number function? I used to have an old >Transactor with a good one in it ("Starts repeatin only after a million >cycles!") but lost the issue. Actually, if a generator has a period of only a million, it's not good enough for serious use. For a good generator, and a good discussion of pseudorandom generators in general, see Stephen K. Park and Keith W. Miller, "Random Number Generators: Good ones are Hard to Find," 10/88 Communications of the ACM. -------------- -- --- --- -=- -- Jeff (martens@cis.ohio-state.edu) Chemlawn, trademark, suburban distributor of toxic chemicals.
@utrcgw.utc.com:mark@ardnt1 (mark) (06/01/90)
on 28 May 90 02:37:51 GMT,
Travers Naran <mindlink!a275> said:
Travers> Sender: amiga-relay-request
<@utrcgw.utc.com:amiga-relay-request@udel.EDU>
Travers> Does anyone have a good random number function? I used to
Travers> have an old Transactor with a good one in it ("Starts repeatin
Travers> only after a million cycles!") but lost the issue.
Travers> --
Travers> -------------------------------------------------------------------
Travers> Travers "T'aran" Naran (I am male)
Travers> Simon Fraser University, Computing Science
Travers> Whovian, Prober, Treker, Quantum Leaper....
Travers> Mailing addresses:
Travers> Usenet Travers_Naran@mindlink.UUCP
Travers> or uunet!van-bc!rsoft!mindlink!Travers_Naran
Travers> ------------------------------------------------------------------
Travers,
Following is a Pascal fragment showing a random-number generator
routine that can be found in the March 1987 issue of Byte (pg 127).
I've only used a few times myself, so I can't make any guarantees,
but it appears to be a good algoritm. I can't answer specifics of
the algorithm, so if you have any questions, get a copy of the
Byte article.
I'm posting this (rather than an Email reply) because I thought
that there might be others that are interested.
Mark
------------------------------------------------------------------------------
| Mark Stucky | Email: |
| United Technologies Research Center | mark%ardnt1@utrcgw.utc.com |
| East Hartford, CT. | mast%utrc@utrcgw.utc.com |
------------------------------------------------------------------------------
Program ...
var x, y, z : integer; { global seeds }
Function random : real;
var temp : real;
begin
{ first generator }
x := 171 * ( x mod 177 ) - 2 * ( x div 177 );
if x < 0 then
x := x + 30269;
{ second generator }
y := 172 * ( y mod 176 ) - 35 * ( y div 176 );
if y < 0 then
y := y + 30307;
{ third generator }
z := 170 * ( z mod 178 ) - 63 * ( z div 178 );
if z < 0 then
z := z + 30323;
{ combine to give function value }
temp := x / 30269.0 + y / 30307.0 + z / 30323.0;
random := temp - trunc( temp );
end;
. . .
begin
{ Initialize seeds. For production runs, different values
[between 1 and 30000] should be used each time, preferably
by some automatic method such as from date and time readings
if available. }
x := 1;
y := 10000;
z := 3000;
. . .
end;