三种方法
<?php
//微秒数的方式
$start = microtime(true);
echo substr(microtime(true), -2).PHP_EOL;
$end = microtime(true);
echo ($end - $start).PHP_EOL;
//mt_rand 随机方式
$start = microtime(true);
echo printf("%02d\n", mt_rand(0, 99));
$end = microtime(true);
echo ($end - $start).PHP_EOL;
//libc rand 随机方式
$start = microtime(true);
echo printf("%02d\n", rand(0, 99));
$end = microtime(true);
echo ($end - $start).PHP_EOL;
运行结果
37
2.1934509277344E-5
82
31.215934753418E-5
55
34.7683715820312E-6