Znalazłem kod w internecie do generowania unikalnych liczb:
<?php
function rand_except($min, $max, $except)
//function returns a random integer between min and max, just like function rand() does.
// Difference to rand is that the random generated number will not use any of the values
// placed in $except. ($except must therefore be an array)
// function returns false if $except holds all values between $min and $max.
{
//first sort array values
sort($except, SORT_NUMERIC
); //calculate average gap between except-values
$except_count = count($except); $avg_gap = ($max - $min + 1 - $except_count) / ($except_count + 1);
if ($avg_gap <= 0)
return false;
//now add min and max to $except, so all gaps between $except-values can be calculated
$except_count += 2;
//iterate through all values of except. If gap between 2 values is higher than average gap,
// create random in this gap
for ($i = 1; $i < $except_count; $i++)
if ($except[$i] - $except[$i - 1] - 1 >= $avg_gap)
return mt_rand($except[$i - 1
] + 1
, $except[$i] - 1
); return false;
}
?>
,jednakże czy jest on efektywny ,czy nie lepiej byłoby po prostu użyć mt_rand() i po prostu porównać występowanie liczby w bazie???Zdaje sobie także sprawę ,że to obciąży bazę poprzez liczne połączenia.Co będzie bardziej przymulać

??Druga ,rzecz czy da rady zapisać wygenerowaną liczbę poprzez polecenie ALTER,czy tylko przez INSERT