acota@pro-realm.cts.com (Arnold Cota) (12/09/90)
How can I get random numbers in Lattice? I use RangeRand and I get the same numbers (real random huh). I want to simulate AD&D dice rolling (D6, D10, etc). Thanks... Arn. UUCP: crash!pro-realm!acota ARPA: crash!pro-realm!acota@nosc.mil INET: acota@pro-realm.cts.com
farren@well.sf.ca.us (Mike Farren) (12/11/90)
acota@pro-realm.cts.com (Arnold Cota) writes: >How can I get random numbers in Lattice? Well, you can use drand(), but I prefer the following (which I've hand-coded in assembler long since, for max speed, but this is the C version): /* Get a random number from 0 - <maxnum>, maxnum < 65536 */ unsigned long randval; void genrand() { randval *= 69069; randval += 69069; } unsigned short rand(maxnum) unsigned short maxnum; { genrand(); return ((unsigned short)(randval & 0x0ffff00) >> 8) % maxnum); } Be sure and set "randval" to some random value before calling genrand(). I use the internal clock. -- Mike Farren farren@well.sf.ca.us