Random attack unique number-php Tutorial

Source: Internet
Author: User
Random generation of unique numbers random generation of unique 6 digits and corresponding 12 digits. for example, we need 10 thousand such as: 244855587753043808558676168139952943 ------ solution ------------------ to record the random data and generate a unique number randomly.
Random generation of unique 6-digit numbers and corresponding 12-digit numbers. for example, 10 thousand digits are required.
For example:
244855 587753043808
558676 168139952943

------ Solution --------------------
Record the random data and compare it at random next time. for now, I only think of this method, but it is very troublesome. I know there are other methods ....
------ Solution --------------------
For ($ I = 10000; $ I <= 99999; $ I ++ ){
Echo "244855 5877530 {$ I}
";
}
------ Solution --------------------
You can generate
PHP code
For ($ I = 0; $ I <30000; $ I ++) {// generates 30 thousand 6-digit digits $ r [] = rand (100000,999 999 );} if (count (array_flip (array_count_values ($ r)> 1) {// Check for repeated exit ('repeated, re-execute ');} foreach (array_chunk ($ r, 3) as $ t) {// cut into three groups $ res [] = array ($ t [0], $ t [1]. $ t [2]); // put it in an array and you can save it as needed} print_r ($ res );
------ Solution --------------------
Discussion

PHP code

$ Check = array ();
For ($ I = 0; I I <30000; $ I ++)
{
Do
{
$ Rnum = rand (100000,999 999 );
}
While (isset ($ check [$ rnum]);
$ Check [$ rnum] = 1;
}
Print_r (array_keys ($ check ));


This generates 10 thousand no ......

------ Solution --------------------
PHP code
    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.