View Full Version : How to Generate Random Numbers?

02-02-2007, 08:11 AM
Hi guys, i have this number, 878777886XXXXXX. The Xs represent random numbers that I want to generate. I want to generate 1000 numbers that does not repeat using php. can anyone help?


02-02-2007, 08:31 AM
We can but don't expect us to just give you the code. What exactly have you tried?

02-02-2007, 01:47 PM

$arr_randoms = array();
$i = 0;
do {
$val = '878777886' . mt_rand(1,999999);
if (!array_key_exists($val, $arr_randoms)) {
$arr_randoms[] = $val;
$i ++;
}while($i < 1000);

would generate an array with 1000 unique, random, elements (stat start with 878777886).
maybe there is a shorter/faster way --> who improves or comes with a more performant alternative?