#18401 [Ana->Csd]: shuffle() broken
| From: | kalowsky@php.net | Date: | Thu, 15 Aug 2002 19:09:55 +0000 |
| Subject: | #18401 [Ana->Csd]: shuffle() broken | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-16929@lists.php.net to get a copy of this message | ||
ID: 18401
Updated by: kalowsky@php.net
Reported By: adam@trachtenberg.com
-Status: Analyzed
+Status: Closed
Bug Type: Arrays related
Operating System: Redhat 7.3
PHP Version: 4CVS-2002-08-12
New Comment:
Fixed in CVS now. Thanks for your patch. Please follow up on any
fallout too :)
Previous Comments:
------------------------------------------------------------------------
[2002-08-14 11:59:51] adam@trachtenberg.com
Yes, this is the Fisher-Yates algorithm. See Perl Cookbook or "perldoc
-f shuffle" for supporting details.
------------------------------------------------------------------------
[2002-08-14 03:27:49] yohgaki@php.net
Oops. Now I see what's the point.
This patch seems good to me. There is no point
changing cur_elem.
Anyone?
------------------------------------------------------------------------
[2002-08-14 03:04:50] yohgaki@php.net
- if (rnd_idx != cur_elem) {
- temp = elems[cur_elem];
- elems[cur_elem] = elems[rnd_idx];
+ RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX);
+ if (rnd_idx != n_left) {
+ temp = elems[n_left];
+ elems[n_left] = elems[rnd_idx];
elems[rnd_idx] = temp;
Thanks for detailed report. This diff clearly show where to fix.
Swapping values requires 3 lines!!
------------------------------------------------------------------------
[2002-08-12 03:10:28] adam@trachtenberg.com
I have just tried it with the latest CVS and I still get the same
results. Brad's changes were in a different section of the file.
------------------------------------------------------------------------
[2002-08-11 02:30:52] kalowsky@php.net
I'm pretty Brad has been playing with this code. Can you test again,
and report back with a new snapshot?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/18401
--
Edit this bug report at http://bugs.php.net/?id=18401&edit=1