隨機發作獨一無二的數字

來源:互聯網
上載者:User
隨機產生獨一無二的數字
隨機產生獨一無二6位的數字和對應的12位元字.比如:需要1萬個
如:
244855 587753043808
558676 168139952943

------解決方案--------------------
把隨機出來的資料記錄下來,下次隨機的時候比對,暫時只想到這麼一個方法,不過很麻煩,曉得有其他方法不....
------解決方案--------------------
For($i=10000;$i<=99999;$i++) {
Echo "244855 5877530{$i}
";
}
------解決方案--------------------
你可以這樣產生
PHP code
for($i=0; $i<30000; $i++) { //產生3萬個6位元  $r[] = rand(100000, 999999);}if(count(array_flip(array_count_values($r)))>1) {//檢查是否有重複  exit('有重複, 重新執行');}foreach(array_chunk($r, 3) as $t) { //切割成3個一組  $res[] = array( $t[0], $t[1].$t[2]); //放到數組, 你根據你的需要進行儲存}print_r($res);
------解決方案--------------------
探討

PHP code

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


這是產生1萬個不……

------解決方案--------------------
PHP code
 
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.