Home  >  Article  >  Backend Development  >  随机发作独一无二的数字

随机发作独一无二的数字

WBOY
WBOYOriginal
2016-06-13 10:52:031066browse

随机产生独一无二的数字
随机产生独一无二6位的数字和对应的12位数字.比如:需要1万个
如:
244855 587753043808
558676 168139952943

------解决方案--------------------
把随机出来的数据记录下来,下次随机的时候比对,暂时只想到这么一个方法,不过很麻烦,晓得有其他方法不....
------解决方案--------------------
For($i=10000;$i Echo "244855 5877530{$i}
";
}
------解决方案--------------------
你可以这样生成

PHP code
for($i=0; $i1) {//检查是否有重复  exit('有重复, 重新执行');}foreach(array_chunk($r, 3) as $t) { //切割成3个一组  $res[] = array( $t[0], $t[1].$t[2]); //放到数组, 你根据你的需要进行保存}print_r($res);<br><font color="#e78608">------解决方案--------------------</font><br>
探讨

PHP code

$check = array();
for($i=0; $i{
do
{
$rnum = rand(100000, 999999);
}
while (isset($check[$rnum]));
$check[$rnum] = 1;
}
print_r(array_keys($check));


这是生成1万个不……

------解决方案--------------------
PHP code
<?php $numbers = range(100000,999999);srand((float)microtime()*1000000);shuffle($numbers);$i = 10000;foreach ($numbers as $number) {    if ($i-- < 0) break;    echo "$number\r\n";}?><div class="clear">
                 
              
              
        
            </div>
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