如何生成唯一的 8 位整数?

Piy*_*iya 0 php random

我想使用 PHP mt_rand() 函数生成一个 8 位随机整数。

我知道 PHP mt_rand() 函数只需要 2 个参数:最小值和最大值。

我该怎么做呢?

Har*_*. A 5

试试这个

$num = str_pad(mt_rand(1,99999999),8,'0',STR_PAD_LEFT);
Run Code Online (Sandbox Code Playgroud)

将 str_pad 与 mt_rand 一起使用