viewing paste Unknown #6118 | C

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
BUILDIN(rand)
{
    int range;
    int min;
    int max;
    
    if( script_hasdata(st,3) )
    {// min,max
        min = script_getnum(st,2);
        max = script_getnum(st,3);
        if( max < min )
            swap(min, max);
        range = max - min + 1;
    }
    else
    {// range
        min = 0;
        range = script_getnum(st,2);
    }
    if( range <= 1 )
        script_pushint(st, min);
    else
        script_pushint(st, rnd()%range + min);
    
    return true;
}
 
Viewed 836 times, submitted by Guest.