- substr: documentation ( source)
- var_dump: documentation ( source)
- str_repeat: documentation ( source)
- str_shuffle: documentation ( source)
- ceil: documentation ( source)
- array_unique: documentation ( source)
<?php
function generateRandomString($length = 22)
{
return substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length);
}
$generated = [];
for ($i = 0; $i < 10000; $i++) {
$generated[] = generateRandomString();
}
var_dump(count(array_unique($generated)));