note 115724 added to function.mt-rand
| From: | JeffCours | Date: | Fri, 12 Sep 2014 22:12:51 +0000 |
| Subject: | note 115724 added to function.mt-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200435@lists.php.net to get a copy of this message | ||
With PHP 5.3.3, we're seeing odd behavior on 32 bit Linux.
This works fine on 64 bit Linux:
<?php
printf ("%08x\n", mt_rand (0, 0xFFFFFFFF));
?>
but on our 32 bit Linux development server, it's always yielding "00000000".
On that same machine, this:
<?php
printf ("%08x\n", mt_rand (0, 0xFFFFFFF0));
?>
seems to always yield either 00000000 or a number in the range fffffff2 to ffffffff. This:
<?php
printf ("%08x\n", mt_rand (0, 0xFFFFFF00));
?>
gives numbers where the last two digits vary, and so on through at least 0xF0000000.
However, this:
<?php
printf ("%08x\n", mt_rand (0, 0x7FFFFFFF));
?>
seems to be well-behaved.
The moral? On 32 bit systems, be careful about crossing the signed number boundary, 0x7FFFFFFF.
----
Server IP: 72.52.91.14
Probable Submitter: 162.202.114.49
----
Manual Page -- http://php.net/manual/en/function.mt-rand.php
Edit -- https://master.php.net/note/edit/115724
Del: integrated -- https://master.php.net/note/delete/115724/integrated
Del: useless -- https://master.php.net/note/delete/115724/useless
Del: bad code -- https://master.php.net/note/delete/115724/bad+code
Del: spam -- https://master.php.net/note/delete/115724/spam
Del: non-english -- https://master.php.net/note/delete/115724/non-english
Del: in docs -- https://master.php.net/note/delete/115724/in+docs
Del: other reasons-- https://master.php.net/note/delete/115724
Reject -- https://master.php.net/note/reject/115724
Search -- https://master.php.net/manage/user-notes.php