mt_rand(~PHP_INT_MAX, PHP_INT_MAX);
Run a couple of times gives me the following output:
php > echo mt_rand(~PHP_INT_MAX, PHP_INT_MAX) . PHP_EOL;
0
php > echo mt_rand(~PHP_INT_MAX, PHP_INT_MAX) . PHP_EOL;
0
php > echo mt_rand(~PHP_INT_MAX, PHP_INT_MAX) . PHP_EOL;
-3445259641993297920
php > echo mt_rand(~PHP_INT_MAX, PHP_INT_MAX) . PHP_EOL;
0
php > echo mt_rand(~PHP_INT_MAX, PHP_INT_MAX) . PHP_EOL;
0
php > echo mt_rand(~PHP_INT_MAX, PHP_INT_MAX) . PHP_EOL;
0
It does not seem very random. Could anyone explain why it so often returns 0? I was expecting a "random" number between the lowest and highst available
Even more, if you change it abit like
echo mt_rand(-PHP_INT_MAX, PHP_INT_MAX)
It will start returning 1 instead of 0
Aucun commentaire:
Enregistrer un commentaire