mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-12 02:08:40 +00:00
All these files need further edits + other optimization files + moving of files
30 lines
580 B
PHP
30 lines
580 B
PHP
<?php
|
|
|
|
class ArrayRandomize
|
|
{
|
|
public static function yates($arr) : array
|
|
{
|
|
$shuffled = [];
|
|
|
|
while($arr){
|
|
$rnd = array_rand($arr);
|
|
$shuffled[] = $arr[$rnd];
|
|
array_splice($arr, $rnd, 1);
|
|
}
|
|
|
|
return $shuffled;
|
|
}
|
|
|
|
public static function knuth($arr) : array
|
|
{
|
|
$shuffled = [];
|
|
|
|
for($i = count($arr)-1; $i > 0; $i--){
|
|
$rnd = mt_rand(0, $i);
|
|
$shuffled[$i] = $arr[$rnd];
|
|
$shuffled[$rand] = $arr[$i];
|
|
}
|
|
|
|
return $shuffled;
|
|
}
|
|
} |