怎么生成不重复的八位数php,请教一下,用PHP如何生成50万个不重复的8位阿拉伯数字?...

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

回复讨论(解决方案)

for( $i = 0 ; $i < 500000; $i++)

for( $i = 10000000 ; $i < 10500000; $i++)

for( $i = 10000000 ; $i < 10500000; $i++)

你也来这里??你不是经常混水区的吗。。。。。

你是干php的?好奇而己。。。。。

function rand_num(&$num){$n = rand(10000000,99999999);if(in_array($n,$num)){rand_num(&$num);}return $n;}for($i=0;$i<500000;$i++){$num[] = rand_num(&$num);}print_r($num);

引用 2 楼 xming4321 的回复:for( $i = 10000000 ; $i < 10500000; $i++)

你也来这里??你不是经常混水区的吗。。。。。

你是干php的?好奇而己。。。。。 我是派黄片的

2楼的最大只能是1049999,显然不符合要求。

4楼的可以。

4楼的慢不慢的?

PHP code?1234567891011121314function rand_num(&$num){ $n = rand(10000000,99999999); if(in_array($n,$num)) { rand_num(&$num); } return $n;}for($i=0;$i<500000;……

瞬间就卡死了 ,不过可以解决要求,哈哈

引用 4 楼 zhangbin1988 的回复:PHP code?1234567891011121314function rand_num(&$num){ $n = rand(10000000,99999999); if(in_array($n,$num)) { rand_num(&$num); } ……

你要循环50W 能不慢嘛?

PHP code?1234567891011121314function rand_num(&$num){ $n = rand(10000000,99999999); if(in_array($n,$num)) { rand_num(&$num); } return $n;}for($i=0;$i<500000;……

郁闷了。。我的PHP版本问题?Call-time pass-by-reference has been removed!!!

rand_num(&$num)

改作

rand_num($num);

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

况且你代码的写法本身就不经合理

2楼的最大只能是1049999,显然不符合要求。

4楼的可以。 你少写了一位吧

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<?php /*  * This file is part of Hashids.  * (c) Ivan Akimov <ivan@barreleye.com>  * For the full copyright and license information, please view the LICENSE  * file that was distributed with this source code.  */ namespace Hashids; use RuntimeException; /**  * This is the math class.  * @author Vincent Klaiber <hello@vinkla.com>  * @author Jakub Kramarz <lenwe@lenwe.net>  */ class Math {     /**      * Add two arbitrary-length integers.      * @param string $a      * @param string $b      * @throws \RuntimeException      * @return string      */     public static function add($a, $b)     {         if (function_exists('gmp_add')) {             return gmp_add($a, $b);         }         if (function_exists('bcadd')) {             return bcadd($a, $b, 0);         }         throw new RuntimeException('Missing BC Math or GMP extension.');     }符串或串(String)是由数母、下划线组成的一串符。一般记为 s=“a1a2···an”(n>=0)。它是编程语言中表示文本的数据类型。在程序设计中,符串(string)为符号或数值的一个连续序列,如符号串(一串符)或二进制数串(一串二进制数)。通常以串的整体作为操作对象,如:在串中查找某个子串、求取一个子串、在串的某个位置上插入一个子串以及删除一个子串等。两个符串相等的充要条件是:长度相等,并且各个对应位置上的符都相等。设p、q是两个串,求q在p中首次出现的位置的运算叫做模式匹配。串的两种最基本的存储方式是顺序存储方式和链接存储方式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值