Created
April 19, 2022 18:15
-
-
Save mmeyer2k/ae6427a9652633ec3fd754d9406a8c5d to your computer and use it in GitHub Desktop.
Secure array_shuffle
This file contains hidden or 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 array_shuffle_secure(array $input): array { | |
$output = []; | |
while ($arr) { | |
$arr = array_values($arr); | |
$char = random_int(0, count($arr) - 1); | |
$output[] = $arr[$char]; | |
unset($arr[$char]); | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment