megabyte@chinet.UUCP (07/20/86)
Does anyone have a good random number generator for use with the Microware 6809 os9 "C" compiler? I'm looking for something like: random = rnd(); /* returns a random number (an int) */ Any taker? ---Dr. Megabyte -- _________________________________________________________________________ UUCP: (1) seismo!why_not!scsnet!sunder Mark E. Sunderlin (2) ihnp4!chinet!megabyte aka Dr. Megabyte CIS: 74026,3235 (202) 634-2529 Quote: "I drank what? " - Socrates (9-4 EDT) Mail: IRS 1111 Constitution Ave. NW PM:PFR:D:NO Washington, DC 20224
dibble@rochester.UUCP (07/21/86)
In article <432@chinet.UUCP>, megabyte@chinet.UUCP (Mark E. Sunderlin) writes: > Does anyone have a good random number generator for use with > the Microware 6809 os9 "C" compiler? > > I'm looking for something like: > random = rnd(); /* returns a random number (an int) */ I wrote this for my port of Hack. It seems to work well (though I haven't made any real effort to validate it). You'll probably have to shrink the constants for the 6809. Check Knuth for directions on picking good numbers. setrandom() /* initialize the seed for random */ { int time, date, tick; short day; _sysdate(2, &time, &date, &day, &tick); srand((time<<8) + (tick & 0xff)); } static unsigned long RandomSeed; srand(seed) int seed; { RandomSeed = (unsigned long)seed; } #define MULTIPLIER 39709L #define INCREMENT 13L #define MODULUS 65537 int rand() { RandomSeed = (RandomSeed * MULTIPLIER + INCREMENT) % MODULUS; return (int)(RandomSeed & 0x7FFFFFFF); }