Update to Random_Compat 1.0.9.

This update includes fixes for Windows support & libSodium support, and removes the `Throwable` Polyfill due to PHP7 incompatibilities. 

Fixes #28633


git-svn-id: https://develop.svn.wordpress.org/trunk@35365 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse
2015-10-23 04:21:01 +00:00
parent b89670b0f6
commit 3a992e266f
11 changed files with 260 additions and 45 deletions
+20 -7
View File
@@ -40,21 +40,34 @@ function random_int($min, $max)
{
/**
* Type and input logic checks
*
* If you pass it a float in the range (~PHP_INT_MAX, PHP_INT_MAX)
* (non-inclusive), it will sanely cast it to an int. If you it's equal to
* ~PHP_INT_MAX or PHP_INT_MAX, we let it fail as not an integer. Floats
* lose precision, so the <= and => operators might accidentally let a float
* through.
*/
if (!is_numeric($min)) {
try {
$min = RandomCompat_intval($min);
} catch (TypeError $ex) {
throw new TypeError(
'random_int(): $min must be an integer'
);
}
if (!is_numeric($max)) {
try {
$max = RandomCompat_intval($max);
} catch (TypeError $ex) {
throw new TypeError(
'random_int(): $max must be an integer'
);
}
$min = (int) $min;
$max = (int) $max;
/**
* Now that we've verified our weak typing system has given us an integer,
* let's validate the logic then we can move forward with generating random
* integers along a given range.
*/
if ($min > $max) {
throw new Error(
'Minimum value must be less than or equal to the maximum value'
@@ -164,7 +177,7 @@ function random_int($min, $max)
/**
* If $val overflows to a floating point number,
* ... or is larger than $max,
* ... or smaller than $int,
* ... or smaller than $min,
* then try again.
*/
} while (!is_int($val) || $val > $max || $val < $min);