Create 10,000 non-repeating random numbers in PHP -


i need work out way create 10,000 non-repeating random numbers in php, , put database table. number 12 digits long.

what best way this?

this assumes can generate 12 digit random number without problems (use getrandmax() see how big can get....according php.net on systems 32k large number can get.

$array = array();  while(sizeof($array)<=10000){   $number = mt_rand(0,999999999999);   if(!array_key_exists($number,$array)){      $array[$number] = null;   } }  foreach($array $key=>$val){   //write array records db. } 

you use either rand() or mt_rand(). mt_rand() supposed faster however.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -