[MUD-Dev] Algorithms for an Infinite Universe

Ola Fosheim Grøstad <olag@ifi.uio.no> Ola Fosheim Grøstad <olag@ifi.uio.no>
Wed Oct 13 22:14:18 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 generate some discussion,
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.

Yeah, but replace Max with a prime (2039 for example) and it should work.

This random generator will hopefully work (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;

/** if 16 bit mod is cheap ***/

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