請教一下,用PHP如何產生50萬個不重複的8位阿拉伯數字?

來源:互聯網
上載者:User
請教一下,用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(&amp;$num){ $n = rand(10000000,99999999); if(in_array($n,$num)) { rand_num(&amp;$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樓的可以。 你少寫了一位吧

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.