Returns array of pseudo random integers of machine-dependent size
public static randomInts ( 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 |
return | integer |
/** * @covers Crypt::randomInts */ public function testRandomInts() { $this->prepareAsync(); Crypt::randomInts(5, function ($ints) { self::assertCount(5, $ints, '$ints must contain 5 elements'); $this->completeAsync(); }); $this->runAsync(__METHOD__); }
/** * Created by PhpStorm. * User: ovr * Date: 06.12.15 * Time: 22:26 */ use Lavoiesl\PhpBenchmark\Benchmark; use Ovr\Bench\AssignOrNot\ReturnAfterAssignProperty; use Ovr\Bench\AssignOrNot\ReturnWithoutAfterAssignProperty; include_once __DIR__ . '/vendor/autoload.php'; $benchmark = new Benchmark(); $benchmark->add('rand', function () { rand(0, getrandmax()); }); $benchmark->add('mt_rand', function () { mt_rand(0, getrandmax()); }); $benchmark->add('random_int', function () { random_int(0, getrandmax()); }); $benchmark->add('phpd-utils-crypt', function () { $gen = false; \PHPDaemon\Utils\Crypt::randomInts(1, function ($result) use(&$gen) { $gen = true; }); while (!$gen) { } }); $benchmark->setCount(100000); $benchmark->run();