I have this code for generate a random positive number:
$token= rand(12132423534, 9285328457237);
Sometimes $token value is a negative number. I think the int value is in overflow.....but wich is the maximum value for not have this error? thanks
The maximum value a PHP integer on a 32-bit Machine is 2147483647
. You need the GMP Extension
for your current scenario.
PHP has getrandmax()
function specially for detecting maximum possible value returned by rand(). BTW, why don't you using mt_rand()
(with mt_getrandmax()), which generates better randoms & faster?