Codice PHP:
$query "SELECT code FROM tabella";
$result mysql_query($query); //ho preso tutti i numeri nella tabella

$numeri = array(); //conterrà i numeri presenti nel db
while($row mysql_fetch_assoc($result)) //finché ci sono record provenienti dalla query precedente
{
    
$numeri[] = $row['code']; //alla fine del ciclo, dentro $numeri ci saranno i numeri presenti nel db
}

$inserito false;
while(!
$inserito)
{
    
$numero rand(1,100);
    if(!
in_array($numero,$numeri))
    {
        
$query "INSERT INTO tabella (code) VALUES ($numero)";
        
$mysql_query($query);
        
$inserito true;
    }