[Home] [Groups] - Message: [Prev in Group] [Next in Group]

nu.kanga.list.mud-dev

11469: Re: [MUD-Dev] Algorithms for an Infinite Universe

[Full Header] [Plain Text]
From: Ola Fosheim Grøstad <olag@ifi.uio.no>
Newsgroups: nu.kanga.list.mud-dev
Date: Fri, 15 Oct 1999 21:01:40 +0100
References: [1] [2] <-newest
Organization: Kanga.Nu
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,
but...):

#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);
}

--
Ola




_______________________________________________
MUD-Dev maillist  -  MUD-Dev@kanga.nu
http://www.kanga.nu/lists/listinfo/mud-dev