Created
April 25, 2020 20:42
-
-
Save m-primo/2306651aee4242788846e37fb7006df9 to your computer and use it in GitHub Desktop.
Random Number by Seed with PHP
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 | |
class Random { | |
// random seed | |
private static $RSeed = 0; | |
// set seed | |
public static function seed($s = 0) { | |
self::$RSeed = abs(intval($s)) % 9999999 + 1; | |
self::num(); | |
} | |
// generate random number | |
public static function num($min = 0, $max = 9999999) { | |
if (self::$RSeed == 0) self::seed(mt_rand()); | |
self::$RSeed = (self::$RSeed * 125) % 2796203; | |
return self::$RSeed % ($max - $min + 1) + $min; | |
} | |
} | |
# ------------------------------------ | |
$seed = time().rand(); | |
var_dump($seed); | |
Random::seed($seed); | |
$min = 1; | |
$max = 10; | |
foreach(range($min, $max*3) as $n) { | |
$sign[] = Random::num($min, $max); | |
} | |
print_r($sign); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment