Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!ucbvax!TAURUS.BITNET!asaph From: asaph@TAURUS.BITNET Newsgroups: comp.sys.amiga Subject: Re:Random Number Generation Message-ID: <1168@taurus.BITNET> Date: 6 Jan 90 23:27:04 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Organization: Tel-Aviv Univesity Math and CS school, Israel Lines: 51 In article <15579@haddock.ima.isc.com> bryanc@haddock.ima.isc.com (Bryan Cote) w > >Simply, does anyone have any suggestions on the best way to generate random >values on the amiga? I am using a public domaine c compiler and have yet >to find a library call to generate random numbers. I've been reading this >newsgroup on and off for a year or so but don't recall seeing this discussed. >Any help will be greatly appreciated, thanks! > >------------------------------------------------------------------------------ The following program uses a random number generator described in communications of the ACM. It is considered a good one. If anyone is interested I might be persuaded to look up the exact issue and author. #define ARAND 16807 #define MRAND 2147483647 #define QRAND 127773 #define RRAND 2836 long RandomSeed; long Random() { long lo,hi,test; hi = RandomSeed/QRAND; lo = RandomSeed%QRAND; test = ARAND*lo + RRAND*hi; if (test>0) RandomSeed = test; else RandomSeed=test+MRAND; return(RandomSeed); } main(argc,argv) int argc; char *argv[]; { int l; long r; if (argc != 2) printf("usage: rand \n"); else { RandomSeed = atol(argv[1]); for (l=0; l<500; l++) { r = Random(); printf("%d) %ld %ld\n",l,r,r%2); } } } Asaph asaph@taurus.bitnet asaph@math.tau.ac.il