Created
September 18, 2012 11:28
-
-
Save fetus-hina/3742682 to your computer and use it in GitHub Desktop.
mt_shuffle(), array_shuffle()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function fy_shuffle(array &$array, $rand = 'mt_rand') { | |
$array = array_values($array); | |
for($i = count($array) - 1; $i > 0; --$i) { | |
$j = $rand(0, $i); | |
if($i !== $j) { | |
list($array[$i], $array[$j]) = array($array[$j], $array[$i]); | |
} | |
} | |
return true; | |
} | |
function mt_shuffle(array &$array) { | |
return fy_shuffle($array, 'mt_rand'); | |
} | |
function array_shuffle(array $array, $rand = 'mt_rand') { | |
fy_shuffle($array, $rand); | |
return $array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment