Generate Random Number in PHP


function refrence_id()
{
    $refrence_id = 'DD'.mt_rand(100000, 999999);
    // check if number already exists in database
    $ref = mysql_query("select count(*) from registration where refrence_id='".$refrence_id."'");
    $refer_no = mysql_fetch_array($ref);
    if($refer_no[0] > 0)
    {
        refrence_id();
    }
    return $refrence_id;
}

$tmpRefID = refrence_id();