- microtime: documentation ( source)
- mt_rand: documentation ( source)
- number_format: documentation ( source)
- rand: documentation ( source)
<?php
function generateRandomName($minLength, $maxLength, $alphaNumericOnly = false)
{
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
if (!$alphaNumericOnly) $chars .= ' ';
$randomString = '';
$length = mt_rand($minLength, $maxLength);
for ($i = 0; $i < $length; $i++)
{
$randomString .= $chars[rand(0, strlen($chars) - 1)];
}
return $randomString;
}
$time = microtime(true);
$i=0;
while($i < 10000)
{
$i++;
$this->generateRandomName(10, 18);
}
$time = microtime(true) - $time;
echo 'took ' . number_format($time, 3);