Random\Randomizer::nextInt
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.2.0)
Get a positive integer
Description
Random\Randomizer::nextInt(): int
Parameters Parameters
Return Values
A positive integer between 0 and a maximum value depending on the number of bytes returned from Random\Engine::generate. The exact maximum can be calculated as 2$engine_bytes * 8 - 1 - 1.
Errors/Exceptions
- To avoid inconsistencies, 32 bit PHP will throw
Random\RandomExceptionif the output size ofRandom\Engine::generateexceeds 32 bits, as the selected integer cannot be returned losslessly. This affects the native 64 bit enginesRandom\Engine\PcgOneseq128XslRr64andRandom\Engine\Xoshiro256StarStar. Any userland engine returning more than 4 bytes of randomness is also affected.
Examples
Random\Randomizer::nextInt() example
php
<?php
$r = new \Random\Randomizer();
// Random "next" integer:
echo $r->nextInt(), "\n";
?>The above example will output something similar to:
output
8041689838856078718