View Full Version : Generate a unique number not already in a list

12-06-2007, 02:21 PM
Hey Davidj,

having a brainfart this afternoon and have a quick question,

i've got an array of values and i want to create a rand num between 1 and 9999 that isn't in the list of vals.

$already_exists = array(1,45,777,23,45);

$pot = rand(0,10000);

if(!in_array($pot, $already_exists)){
//use pot

through me a lifeline bigman! haha

12-06-2007, 02:54 PM
no worries i've got a solution:

$already_exists = array(1,3,4,6,7,8);

do $pot = rand(0,10000);
while(in_array($pot, $already_exists));

echo $pot;

12-06-2007, 05:05 PM
through me a lifeline bigman! haha

big man eh

ill have you know im in shape

its a round shape i admit but its a shape!