mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
Moving to RnG
This commit is contained in:
parent
78bc28b045
commit
776717ad53
|
|
@ -1,30 +0,0 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
class LinearCongruentialGenerator
|
||||
{
|
||||
public static function bsd(int $seed)
|
||||
{
|
||||
return function() use(&$seed) {
|
||||
return $seed = (1103515245 * $seed + 12345) % (1 << 31);
|
||||
}
|
||||
}
|
||||
|
||||
public static function msvcrt(int $seed) {
|
||||
return function() use (&$seed) {
|
||||
return ($seed = (214013 * $seed + 2531011) % (1 << 31)) >> 16;
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user