note 53569 added to function.shuffle
| From: | skissane at iips dot mq dot edu dot au | Date: | Mon, 06 Jun 2005 10:11:31 +0000 |
| Subject: | note 53569 added to function.shuffle | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90000@lists.php.net to get a copy of this message | ||
note that in PHP 5.0.4 (and assumably earlier versions as well), shuffle internally calls rand(),
not mt_rand().
This was important because I was trying to use a fixed seed to get repeatable results, by calling
mt_srand(). But of course that doesn't work, since shuffle uses rand() not mt_rand(). The
solution is either to use srand() for seeding, or to write your own version of shuffle() using
mt_rand(). (See examples which others have contributed; or, just have a look at
ext/standard/array.c) mt_rand on many platforms gives better results than the builtin library
anyway...
N.B. Obviously, the way the shuffle function is implemented may change without notice in future
versions, including e.g. changing to use mt_rand instead.
----
Manual Page -- http://www.php.net/manual/en/function.shuffle.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+53569
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53569&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53569&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53569&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53569&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53569&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+53569&report=yes
Search -- http://master.php.net/manage/user-notes.php