Definition at line 34 of file Math.php.
◆ btwoc()
Get the big endian two's complement of a given big integer in binary notation
- Parameters
-
- Returns
- string
Definition at line 161 of file Math.php.
163 if (ord($long[0]) > 127) {
164 return "\x00" . $long;
◆ fromBinary()
Translate a binary form into a big integer string
- Parameters
-
- Returns
- string
Definition at line 175 of file Math.php.
177 return $this->_math->binaryToInteger($binary);
◆ rand()
rand |
( |
|
$minimum, |
|
|
|
$maximum |
|
) |
| |
Generate a pseudorandom number within the given range. Will attempt to read from a systems RNG if it exists or else utilises a simple random character to maximum length process. Simplicity is a factor better left for development...
- Parameters
-
string | int | $minimum | |
string | int | $maximum | |
- Returns
- string
Definition at line 47 of file Math.php.
49 if (file_exists(
'/dev/urandom')) {
50 $frandom =
fopen(
'/dev/urandom',
'r');
51 if ($frandom !==
false) {
52 return fread($frandom, strlen($maximum) - 1);
55 if (strlen($maximum) < 4) {
56 return mt_rand($minimum, $maximum - 1);
59 $i2 = strlen($maximum) - 1;
60 for (
$i = 1;
$i < $i2;
$i++) {
61 $rand .= mt_rand(0, 9);
63 $rand .= mt_rand(0, 9);
◆ randBytes()
static randBytes |
( |
|
$length, |
|
|
|
$strong = false |
|
) |
| |
|
static |
Return a random strings of $length bytes
- Parameters
-
integer | $length | |
boolean | $strong | |
- Returns
- string
Definition at line 74 of file Math.php.
76 $length = (int) $length;
81 return random_bytes($length);
84 $bytes = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
85 if ($bytes !==
false && strlen($bytes) === $length) {
89 if (file_exists(
'/dev/urandom') &&
is_readable(
'/dev/urandom')) {
90 $frandom =
fopen(
'/dev/urandom',
'r');
91 if ($frandom !==
false) {
92 return fread($frandom, $length);
95 if (
true === $strong) {
96 require_once
'Zend/Crypt/Exception.php';
98 'This PHP environment doesn\'t support secure random number generation. ' .
99 'Please consider installing the OpenSSL and/or Mcrypt extensions' 103 for (
$i = 0;
$i < $length;
$i++) {
104 $rand .= chr(mt_rand(0, 255));
◆ randInteger()
static randInteger |
( |
|
$min, |
|
|
|
$max, |
|
|
|
$strong = false |
|
) |
| |
|
static |
Return a random integer between $min and $max
- Parameters
-
integer | $min | |
integer | $max | |
boolean | $strong | |
- Returns
- integer
Definition at line 117 of file Math.php.
120 require_once
'Zend/Crypt/Exception.php';
122 'The min parameter must be lower than max parameter' 125 $range = $max - $min;
128 }
elseif ($range > PHP_INT_MAX || is_float($range)) {
129 require_once
'Zend/Crypt/Exception.php';
131 'The supplied range is too great to generate' 135 return random_int($min, $max);
144 $bits = (int) max($bits, 1);
145 $bytes = (int) max(ceil($bits / 8), 1);
146 $filter = (int) ((1 << $bits) - 1);
148 $rnd = hexdec(bin2hex(self::randBytes($bytes, $strong)));
150 }
while ($rnd > $range);
151 return ($min + $rnd);
elseif(isset( $params[ 'redirect_parent']))
◆ toBinary()
Translate a big integer string into a binary form
- Parameters
-
- Returns
- string
Definition at line 186 of file Math.php.
188 return $this->_math->integerToBinary($integer);
The documentation for this class was generated from the following file:
- vendor/magento/zendframework1/library/Zend/Crypt/Math.php