June 24th, 1999, 06:40 PM
I am using the rand() function in php3. Without arguments it seems to behave as advertised, returning an integer between 0 and getrandmax(). It seems to behave the same way with arguments, though, e.g. rand(1,15) -> 1774965089, rather than a number between 1 and 15.
This is not because I haven't seeded the generator --- I use srand as in the manual before I start making calls to rand.
Also, this would OK if there were a modulus function (e.g. rand() mod 15), but I don't see one in the math section of the manual.
Any help appreciated.
June 24th, 1999, 07:03 PM
Ooops, modulus is an operator ('%').
rand() still seems to ignore its args, but if anyone else has the same problem, a workaround is something like
function rand_with_args($min, $max)
return ($min + rand() % (1 + $max - $min));
June 25th, 1999, 02:59 PM
Replying to myself once again --- the rand() bug was apparently fixed as of PHP version 3.0.7.