Skip to content

Instantly share code, notes, and snippets.

@KasaiMagi
Created May 7, 2013 19:55
Show Gist options
  • Save KasaiMagi/5535596 to your computer and use it in GitHub Desktop.
Save KasaiMagi/5535596 to your computer and use it in GitHub Desktop.
<?php
$startTime = time();
$finalResults = array();
for ($j = 0; $j < 1000000; $j++) {
do {
$candidate = getToken();
} while (array_key_exists($candidate, $finalResults));
$finalResults[$candidate] = 1;
}
$endTime = time();
print 'done' . PHP_EOL;
print 'Time Elapsed: ' . gmdate("H:i:s", $endTime - $startTime) . PHP_EOL;
function getToken($length = 8)
{
$firstChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$result = $firstChar[mt_rand(0, strlen($firstChar)-1)];
$remainingLength = $length - 1;
for ($i = 0; $i < $remainingLength; $i++) {
$result .= $chars[mt_rand(0, strlen($chars)-1)];
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment