#25247 [Opn->Fbk]: Shuffle() method doesn't work properly

From: Date: Tue, 26 Aug 2003 12:17:10 +0000
Subject: #25247 [Opn->Fbk]: Shuffle() method doesn't work properly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-46677@lists.php.net to get a copy of this message
ID: 25247 Updated by: iliaa@php.net Reported By: jeroen at kesh dot nl -Status: Open +Status: Feedback Bug Type: Arrays related Operating System: Windows 2000 Server PHP Version: 4.3.3 New Comment: Try calling srand(time()); before the shuffle. Previous Comments: ------------------------------------------------------------------------ [2003-08-26 05:44:58] jeroen at kesh dot nl Description: ------------ I pick the first two products out of the shuffled array for random productviews on a page. I use 3 or more products. With PHP 4.3.2 it works nice (every refresh another two products). With PHP 4.3.3 it doesn't seem to work. Every time the same products. Same PHP.INI file as 4.3.2 (which worked fine). Reproduce code: --------------- $ads = array(); while($product = mysql_fetch_array($arts)) { $ads[] = $product; } shuffle($ads); $prod = $ads[0]; echo ($prod[name]); $prod = $ads[1]; echo ($prod[name]); Expected result: ---------------- The first two array-records are other products every time at refresh. Actual result: -------------- The first two array-records are the same products each refresh. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=25247&edit=1

« previous php.bugs (#46677) next »