产生一个N位数的随机数 [英] Generate an N-digit random number
本文介绍了产生一个N位数的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用PHP mt_rand()
函数生成一个6位数的随机数.
I want to generate a 6 digit random number using the PHP mt_rand()
function.
我知道PHP mt_rand()
函数仅需要2个参数: minimum 和 maximum 值.
I know the PHP mt_rand()
function only takes 2 parameters: a minimum and a maximum value.
我该怎么做?
推荐答案
像这样的事情?
<?php
$a = mt_rand(100000,999999);
?>
否则,在第一个示例中,第一个数字可以为0,只能为1到9
Or this, then the first digit can be 0 in first example can it only be 1 to 9
for ($i = 0; $i<6; $i++)
{
$a .= mt_rand(0,9);
}
这篇关于产生一个N位数的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文