I'm trying to generate a process in order to create aproximately 5000 unique keys into a table with rand_md5 function. Sometimes it is giving a repeated "unique" key constraint violation. What can I do to solve this?
function rand_md5($length) {
$max = ceil($length / 32);
$random = '';
for ($i = 0; $i < $max; $i ++) {
$random .= md5(microtime(true).mt_rand(10000,90000));
}
return substr($random, 0, $length);
This function is called inside a for loop from 1 to 5000 iterations (for example).
Any ideas how to solve this?