[MUD-Dev] Algorithms for an Infinite Universe

Ola Fosheim Grøstad <olag@ifi.uio.no> Ola Fosheim Grøstad <olag@ifi.uio.no>
Fri Oct 15 21:01:40 New Zealand Daylight Time 1999

Quzah wrote:
> Is it just me, or is this guy totally, 100% wrong? I've
> tried both by following his explanation, and by just taking
> his code, to get his pesudo-random number generator to
> work, and it doesn't. He's wrong.

Ack... I only skimmed the article. Hoped it would stimulate some discussion
on the topic, not this kind of discussion though. :(

> A quick copy-paste into a text file and his pseudo-random
> generator returns all zeros for the random numbers. Sad.

Yes. Very sad, but replace Max with a prime (2039 for example) and it may
work.  Random generators are not my speciality, but here are some examples
that ought to work without too much pain (haven't tried it in five years,

#define RND_A 16807
#define RND_M 2147483647
#define RND_Q 127773
#define RND_R 2836
/* RND_Q = M DIV A  RND_R = M MOD A */

long rnd_seed;

long random(){
    long tmp_seed;
    tmp_seed = RND_A * (rnd_seed % RND_Q) - RND_R*(rnd_seed/RND_Q);
    rnd_seed = (tmp_seed >= 0 ? tmp_seed : tmp_seed + RND_M);
    return rnd_seed;

/** a simple random for 16 bit mod ***/

unsigned short frnd_seed;
unsigned short frnd_a;
#define FRND_A 17
#define FRND_M 65521

unsigned short fastrandom(){
    return frnd_seed = (unsigned short)(((unsigned long)FRND_A *frnd_seed)
                       % (unsigned short)FRND_M);


MUD-Dev maillist  -  MUD-Dev at kanga.nu

More information about the MUD-Dev mailing list