[155] in Coldmud discussion meeting

root meeting help first previous next last

random(0) bugfix

daemon@ATHENA.MIT.EDU (Tue Mar 22 14:09:45 1994 )

From: zachary@io.com (Zachary )
To: coldstuff@MIT.EDU
Date: Tue, 22 Mar 94 13:04:54 CST


After a bit of consulting, and realizing that this can be changed later, here's 
a bugfix for the random() bug... replace the op_random() function that's in 
miscops.c with this one:

void op_random(void)
{
    Data *args;

    /* Take one integer argument. */
    if (!func_init_1(&args, INTEGER))
        return;

    /* Do range checking */
    if (args[0].u.val <= 0) {
       throw(range_id,"Argument to random() must be greater than zero.");
    } else {
       /* Replace argument on stack with a random number. */
       args[0].u.val = random_number(args[0].u.val);
    }
}

and all should be well - it is a range error to hand random() a range less than one...

 --Zachary