<?php
echo "<pre>";

$start = microtime(true);
$end = microtime(true);
$rand = [];
$i = 0;
do{
    $theRand = mt_rand(0,99999);
    if(in_array($theRand,$rand)){
        $i=$i+1;
    }
    $rand[] = $theRand;
    $end = microtime(true);
}while(($end-$start)<1);

echo $i;
echo "<br>";
echo count($rand);
?>

多次测试后,

当随机数为 0 - 99999 时,每秒约能生成 25000 个随机数,重复的约为 3000

当随机数为 0 - 999999 时,每秒约能生成 25000 个随机数,重复的约为 300

机数为 0 - 9999999 时,每秒约能生成 25000 个随机数,重复的约为 30

一秒钟内生成两个随机数撞车的概率还是蛮大的

起因是做活动,订单号貌似重复了,高峰期一分钟八单

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注