You can try
for($i = 0; $i < 10 ; $i++)
{
echo randString(5),PHP_EOL ;
}
Output
7fh96
G93fd
97Q7E
90Wku
7Vby9
4678f
S11oe
67688
19D36
KC1bQ
Simple Collision Test
$hash = array();
$collision = 0;
while ( count($hash) < 220000 ) {
$r = randString(5);
if (isset($hash[$r])) {
$collision ++;
continue;
}
$hash[$r] = 1;
}
print(($collision / 220000) * 100 . "% - ($collision)");
Tested 100,000 times and always collision is always less that 0.02 which makes the function efficient for a 5 character set
0.011818181818182% - (26)
Function Used
function randString($length) {
$char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$char = str_shuffle($char);
for($i = 0, $rand = '', $l = strlen($char) - 1; $i < $length; $i ++) {
$rand .= $char{mt_rand(0, $l)};
}
return $rand;
}