try this, i use something similar to generate random passwords which i then email to users.
function generate_id()
{
$salt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
srand((double)microtime()*1000000);
$id = "";
//generates random 6 character id
for($count = 0; $count < 6; $count++)
{
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$id = $id.$tmp;
}
return $id;
}
$randid = generate_id();