A question about super-long non-repeated random sequence

Source: Internet
Author: User
An issue about super-long non-repeated random sequence is written as one in the range of 10000000 ~ Within the range of 90000000, a non-repeating sequence with 100000 metrics is generated. & lt ;? Php $ seedarraymicrotime (); & nbsp; $ seedstrsplit (& quot;, $ seedarray, 5); & nbsp; $ seed $ seedstr [0] * 10000; & a long, non-repeating random sequence problem
Worker Writes one in 10000000 ~ Generate a non-repeating sequence with up to 90000000 entries in the range of 100000

$ Seedarray = microtime ();
$ Seedstr = split ("", $ seedarray, 5 );
$ Seed = $ seedstr [0] * 10000;
Srand ($ seed );
$ Numberarr = array ();
For ($ I = 0; I I <100000 ;){
$ Newnumber = rand (10000000) +;

If (! In_array ($ newnumber, $ numberarr )){
Array_push ($ numberarr, $ newnumber );
$ I ++;
Echo $ I ,'
';
}


}
?>

Finally, the program crashed APACHE at 32202... I don't know why ..

C # write similar algorithms

Private void button#click (object sender, EventArgs e)
{
Thread t = new Thread (tt );
T. IsBackground = true;
T. Start ();

}
Private void tt (){
For (int I = 0; I <100000 ;)
{
String temp = r. Next (0, 80000000). ToString ();;
If (! L. Contains (temp ))
{
L. Add (temp );
I ++;

}


}
MessageBox. Show ("0 k ");
}

No problem

However, when a label is accessed across threads to monitor variable I, the label of C # also has an exception ..
I don't know if I did something wrong, or is there any other solution?

------ Solution --------------------
After a try, I got to 31408.
------ Solution --------------------
The maximum value of int in php is 32769. It may be because of overflow.
PHP code
  ';}}?>
------ Solution --------------------
PHP code
ini_set("max_execution_time", 600);$seedarray =microtime();$seedstr =split(" ",$seedarray,5);$seed =$seedstr[0]*10000;srand($seed);$numberarr= array();for($i=0;$i <100000;){    $newnumber=rand(0,80000000)+10000000;    if(!in_array($newnumber,$numberarr)){        array_push($numberarr,$newnumber);        $i++;        echo $i,' 
'; if ($i%1000==0) flush(); } }?>

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.