Mohammed Adamu

Mohammed Adamu

  • NA
  • 107
  • 48k

How to generate unique random numbers using php

Feb 20 2017 9:34 PM
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();
 "   

Answers (8)