[MUD-Dev] Random numbers (was: Physics)

Eli Stevens {Grey} ens017 at mizzou.edu
Mon Nov 15 14:31:34 CET 1999


It always takes me forever to reply to the messages i'm interested in...
sigh.  :)

----- Original Message -----
From: Mik Clarke <mikclrk at attglobal.net>
Subject: Re: [MUD-Dev] Physics
>
> I suspect that the simulations might get more detailed, giving more
> realistic results, but the limits on the information that can be sent
> to the client mean that it will have to fill in a lot of the detail
> itself.
>
> Consider two people fighting with swords, when one of the parries the
> other and his sword shatters.
>
> Event wise:
>
>   bubba attacks buffo
>   buffo parries bubbas attack
>   buffos sword shatters!
>
> Now, suitably encoded, these can be parsed by an intelligent client to
> draw pretty pictures of bubba swining, buffo parrying and buffos sword
> shattering into a throusand fragments.  Granted the details will be
> different for each viewer, but the overall events will be the same.

The RNG below is pretty nifty (I haven't actually used it yet, but I like
its features).  I basically copied and pasted this off of the CD that came
with the book "Inner Loops" by Rick Booth (good book, from the P-100 era).
What the RNG does is take two seeds, one that stays constant, and one that
acts as an index into the random number sequence.  It allows generating the
sequence of numbers out of sequence (leave the index at 1 to get the first
number every time, increase it by 10 each time, whatever).

For example:

    Boffo tries to backstab Bubba
    -- server says that attack will be attempted at time t1 (*see below)
    -- t1 is used as index into the random number sequence, backstab fails
    -- Boffo's client and server both determine it failed independantly
    -- Bubba does not "see" the attempt, and no information is sent to Bubba
about it
    Bubba attacks Boffo at time t2
    -- server assigns time
    Boffo parries attack with index t2 (assuming that Bubba and Boffo have
different seeds)
    ...  etc.

The fact that Boffo generated an extra number that Bubba does not know about
does not matter.  All Bubba, Boffo and the server need are the players
skills, a server generated seed, and the time something happens.  Of course,
it would probably be a good idea to not have other players' skills available
to the client, but...  :)

 (*exact t1 should be determined by the server, so hacked clients cannot
send attacks only when the attack will succeed.)

---start code---

extern unsigned long IL_HashRandom_seed;
extern unsigned long IL_HashRandom_index;
extern unsigned long IL_HashRandom_reps;

long IL_HashRandom_C()
{
    static long xormix1[] = {
                0xbaa96887, 0x1e17d32c, 0x03bcdc3c, 0x0f33d1b2,
                0x76a6491d, 0xc570d85d, 0xe382b1e3, 0x78db4362,
                0x7439a9d4, 0x9cea8ac5, 0x89537c5c, 0x2588f55d,
                0x415b5e1d, 0x216e3d95, 0x85c662e7, 0x5e8ab368,
                0x3ea5cc8c, 0xd26a0f74, 0xf3a9222b, 0x48aad7e4};

    static long xormix2[] = {
                0x4b0f3b58, 0xe874f0c3, 0x6955c5a6, 0x55a7ca46,
                0x4d9a9d86, 0xfe28a195, 0xb1ca7865, 0x6b235751,
                0x9a997a61, 0xaa6e95c8, 0xaaa98ee1, 0x5af9154c,
                0xfc8e2263, 0x390f5e8c, 0x58ffd802, 0xac0a5eba,
                0xac4874f6, 0xa9df0913, 0x86be4c74, 0xed2c123b};

    unsigned long hiword, loword, hihold, temp, itmpl, itmph, i;

    loword = IL_HashRandom_seed;
    hiword = IL_HashRandom_index++;
    for (i = 0; i < IL_HashRandom_reps; i++) {
        hihold  = hiword;                           // save hiword for later
        temp    = hihold ^  xormix1[i];             // mix up bits of hiword
        itmpl   = temp   &  0xffff;                 // decompose to hi & lo
        itmph   = temp   >> 16;                     // 16-bit words
        temp    = itmpl * itmpl + ~(itmph * itmph); // do a multiplicative
mix
        temp    = (temp >> 16) | (temp << 16);      // swap hi and lo halves
        hiword  = loword ^ ((temp ^ xormix2[i]) + itmpl * itmph); // loword
mix
        loword  = hihold;                           // old hiword is loword
    }
    return hiword;
}

---end code --

Just something to think about.  :)

Silence is golden
Eli - mailto:ens017 at mizzou.edu
Don't mind banner ads?  Get paid to surf the web:
http://www.alladvantage.com/go.asp?refid=DZU770





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



More information about the mud-dev-archive mailing list