Home  >  Article  >  Backend Development  >  请问一下,用PHP怎么生成50万个不重复的8位阿拉伯数字

请问一下,用PHP怎么生成50万个不重复的8位阿拉伯数字

WBOY
WBOYOriginal
2016-06-13 11:19:27834browse

请教一下,用PHP如何生成50万个不重复的8位阿拉伯数字?
请教一下,用PHP如何生成50万个不重复的8位阿拉伯数字。代码怎么样写?求帮助?急。。求完整的代码。自动回车空行。。谢谢各位前辈。。

php 随机数
------解决方案--------------------
<br />function rand_num(&$num)<br />{<br />	$n = rand(10000000,99999999);<br />	if(in_array($n,$num))<br />	{<br />		rand_num(&$num);<br />	}<br />	return $n;<br />}<br />for($i=0;$i<500000;$i++)<br />{<br />	$num[] = rand_num(&$num);<br />}<br />print_r($num);<br />

------解决方案--------------------
本帖最后由 xuzuning 于 2013-03-10 07:31:50 编辑 rand_num(&$num)
改作
rand_num($num);

php 5.3 起,不能显式的传递引用

况且你代码的写法本身就不经合理
------解决方案--------------------
引用:
2楼的最大只能是1049999,显然不符合要求。
4楼的可以。
你少写了一位吧
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn