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(); } }?>