'random_int(): $min must be an integer'
);
}
+
try {
$max = RandomCompat_intval($max);
} catch (TypeError $ex) {
'Minimum value must be less than or equal to the maximum value'
);
}
+
if ($max === $min) {
return $min;
}
* Test for integer overflow:
*/
if (!is_int($range)) {
+
/**
* Still safely calculate wider ranges.
* Provided by @CodesInChaos, @oittaa
*/
$bytes = PHP_INT_SIZE;
$mask = ~0;
+
} else {
+
/**
* $bits is effectively ceil(log($range, 2)) without dealing with
* type juggling
* then try again.
*/
} while (!is_int($val) || $val > $max || $val < $min);
+
return (int) $val;
}