Skip to content

Commit

Permalink
Raise SimpleRandom max to PHP_INT_MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed May 5, 2023
1 parent eb32c64 commit 53bc88f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ReverseRegex/Random/SimpleRandom.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct($seed = null)
public function max($value = null)
{
if($value === null && $this->max === null) {
$max = 2147483647;
$max = PHP_INT_MAX;
}
elseif($value === null) {
$max = $this->max;
Expand Down Expand Up @@ -94,23 +94,23 @@ public function seed($seed = null)
* Generate a random numer
*
* @param integer $max
* @param integer $max 2,796,203 largest possible max
* @param integer $max PHP_INT_MAX largest possible max
*/
public function generate($min = 0, $max = null)
{
if($max === null) {
$max = 2796203;
$max = PHP_INT_MAX;
}

if($max > 2796203) {
throw new ReverseRegexException('Max param has exceeded the maxium 2796203');
if($max > PHP_INT_MAX) {
throw new ReverseRegexException('Max param has exceeded the maxium ' . PHP_INT_MAX);
}

if ($this->seed == 0) {
$this->seed(mt_rand());
}

$this->seed = ($this->seed * 125) % 2796203;
$this->seed = ($this->seed * 125) % PHP_INT_MAX;


return $this->seed % ($max - $min + 1) + $min;
Expand Down

0 comments on commit 53bc88f

Please sign in to comment.