# Random\Randomizer::nextInt

(PHP 8 >= 8.2.0)

Random\Randomizer::nextInt — Get a positive integer

### 说明

public Random\Randomizer::nextInt(): int

### 参数

此函数没有参数。

### 返回值

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.

### 错误／异常

- To avoid inconsistencies, 32 bit PHP will throw Random\RandomException if the output size of Random\Engine::generate() exceeds 32 bits, as the selected integer cannot be returned losslessly. This affects the native 64 bit engines Random\Engine\PcgOneseq128XslRr64 and Random\Engine\Xoshiro256StarStar. Any userland engine returning more than 4 bytes of randomness is also affected.
- 底层 `Random\Randomizer::$engine` 的 Random\Engine::generate() 方法抛出的任何 Throwable。

### 示例

示例 #1 Random\Randomizer::nextInt() example

`<?php
$r = new \Random\Randomizer();
// Random "next" integer:
echo $r->nextInt(), "\n";
?>`

以上示例的输出类似于：

    8041689838856078718

`↑` and `↓` to navigate • `Enter` to select • `Esc` to close • `/` to open