View Single Post
Old 06-11-2008, 02:21 PM   #10 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 710
Thanks: 2
Salathe is on a distinguished road
Default

I'm not really talking about optimising the code, in the sense of squeezing out that last microsecond of runtime, or saving that extra CPU cycle here and there. My main point was that much of what you wrote appears to have been unnecessary for the functionality of the code. Case in point, the multiple calls to shuffle.

From my understanding (which may be wrong!), shuffling an array multiple times doesn't make the values inside it any more randomly placed than simply shuffling once -- I'd be happy to see any tests done to determine the actual behaviour, if indeed the array is 'more random'. Because of that, I feel that shuffling more than once isn't necessary. Indeed, the entire point of shuffling the array (to randomise the values) is a non-point because the values are selected at random later using mt_rand. What's the advantage of selecting a random value from a shuffled array over selecting a random value from an ordered array? I don't see any, maybe you do.

I'll repeat, I'm not looking to optimise the code for ultimate performance but instead trying to get across the idea of good practises. There's no good point that I can think of (feel free to point any out!) as to why it's a good idea to shuffle the array once, twice, twenty times.

Take out the code block under "shake it around abit" and does the function perform any differently? Are the echoed/returned strings any less random?
__________________
Salathe is offline  
Reply With Quote