Please i need help on how to generate highly unique id for my php program, i have one which is doing that but after about 190 unique numbers it started to repeat itself which is making the unique column in the database problematic. please here is my code code if there is something i did wrong please help me correct it thanks. " function uniqids() {
$chars = "003232303232023232023456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$finalcode='RS-'.uniqids();
"
Kesavan KrishnanRank #3,055 · 471 reputationPosted May 28, 2017, 9:06 PM EDT
Bryian TanRank #396 · 6.3K reputationPosted Feb 20, 2017, 4:52 PM EST
$num = rand(1000000, 99999999) %33;Mohammed Adamu117 reputationPosted Feb 20, 2017, 5:02 PM EST
$num = rand(1000000, 99999999) %33; i have added it but i think it still generating but what is the assurance that it will not repeat itself. Thanks a lot.Bryian TanRank #396 · 6.3K reputationPosted Feb 20, 2017, 5:24 PM EST
Mohammed Adamu117 reputationPosted Feb 20, 2017, 6:26 PM EST
Mohammed Adamu117 reputationPosted May 29, 2017, 8:18 AM EDT
Kesavan KrishnanRank #3,055 · 471 reputationPosted May 29, 2017, 9:52 PM EDT
for($i = 0; $i<100; $i++){
$unique[$i] = md5(uniqid(mt_rand(), true).microtime(true));
echo $unique[$i].PHP_EOL;
}
print_r(array_diff($unique, array_unique($unique)));
?>
Mohammed Adamu117 reputationPosted May 30, 2017, 2:28 AM EDT