note 86368 added to function.array-rand
| From: | alvaro at demogracia dot com | Date: | Wed, 15 Oct 2008 11:34:21 +0000 |
| Subject: | note 86368 added to function.array-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-145373@lists.php.net to get a copy of this message | ||
As of PHP/5.2.6, array_rand() is not reliable in Windows (see bug #45301):
<?php
$data = range(1, 20000);
for($i=0; $i<10; $i++){
echo array_rand($data) . "\n";
}
?>
This prints something like:
7735
15498
3590
13677
15498
3590
13677
15498
3590
13677
You only get 4 different values when choosing among 20,000.
I suggest you build your own random picker and base it in mt_rand().
----
Server IP: 80.64.47.13
Probable Submitter: 80.37.14.51
----
Manual Page -- http://www.php.net/manual/en/function.array-rand.php
Edit -- https://master.php.net/note/edit/86368
Del: integrated -- https://master.php.net/note/delete/86368/integrated
Del: useless -- https://master.php.net/note/delete/86368/useless
Del: bad code -- https://master.php.net/note/delete/86368/bad+code
Del: spam -- https://master.php.net/note/delete/86368/spam
Del: non-english -- https://master.php.net/note/delete/86368/non-english
Del: in docs -- https://master.php.net/note/delete/86368/in+docs
Del: other reasons-- https://master.php.net/note/delete/86368
Reject -- https://master.php.net/note/reject/86368
Search -- https://master.php.net/manage/user-notes.php