public static randomInts32 ( integer $numInts, callable $cb, integer $pri, boolean $hang = false ) : integer | ||
$numInts | integer | Number of integers |
$cb | callable | Callback |
$pri | integer | Priority of EIO operation |
$hang | boolean | If true, we shall use /dev/random instead of /dev/urandom and it may cause a delay |
Résultat | integer |
public static function randomInts32($numInts, $cb, $pri = 0, $hang = false)
{
static::randomBytes(4 * $numInts, function ($bytes) use($cb, $numInts) {
if ($bytes === false) {
$cb(false);
return;
}
$ints = [];
for ($i = 0; $i < $numInts; ++$i) {
$thisInt = 0;
for ($j = 0; $j < 4; ++$j) {
$thisInt = $thisInt << 8 | ord($bytes[$i * 4 + $j]) & 0xff;
}
// Absolute value in two's compliment (with min int going to zero)
$thisInt = $thisInt & 0xffffffff;
$ints[] = $thisInt;
}
$cb($ints);
}, $pri, $hang);
}
/** * Constructor * @return void */ public function init() { parent::init(); Crypt::randomInts32(1, function ($ints) { $this->opts['entropy'] = $ints[0]; echo json_encode($this->opts); $this->finish(); }, 9); $this->sleep(5, true); }