Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!im4u!ut-sally!husc6!yale!decvax!decwrl!pyramid!hplabs!tektronix!uw-beaver!cornell!rochester!dibble From: dibble@rochester.UUCP Newsgroups: net.micro.6809 Subject: Re: Wanted: rnd() for os9 "C" Message-ID: <19544@rochester.ARPA> Date: Mon, 21-Jul-86 11:55:29 EDT Article-I.D.: rocheste.19544 Posted: Mon Jul 21 11:55:29 1986 Date-Received: Wed, 23-Jul-86 07:16:18 EDT References: <432@chinet.UUCP> Distribution: net Organization: U of Rochester, CS Dept., Rochester, NY Lines: 36 Summary: Simple random # generator for OS-9 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); }