View Single Post
Old 11-27-2007, 03:12 AM   #2 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Good tip! There is also the array_rand way. However, as I was trying it just now, it seems to love its zeros, so I decided to do a little test as well. This is the array_rand code:

php Code:
$aFilms = array("V For Vendetta", "Requiem For A Dream", "Jacob's Ladder");
echo $aFilms[array_rand($aFilms)];

And this is my test code as it appeared to be quite fond of returning zero:

php Code:
$aCount = array(0, 0, 0);
$aFilms = array("V For Vendetta", "Requiem For A Dream", "Jacob's Ladder");

for($iIndex = 0; $iIndex <= 5000; $iIndex++)
{
    $aCount[array_rand($aFilms)]++;
}

print_r($aCount);

Results were quite surprising as I thought zero would have been much more dominant:

Quote:
Array
(
[0] => 1701
[1] => 1637
[2] => 1663
)
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote