Last active
December 28, 2015 04:58
-
-
Save samundra/7446003 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function generateUsername() { | |
$small = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); | |
$capital = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); | |
$numbers = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); | |
$f = rand(0, 25); | |
$s = rand(0, 25); | |
$firstPart = $small[$f] . $small[$s]; | |
$secondPart = $capital[$f] . $capital[$s]; | |
if (($f > 0 && $f < 10) && ($s > 0 && $s < 10)) { | |
$thirdPart = $numbers[$f] . $numbers[$s]; | |
} else { | |
$f = rand(0, 9); | |
$s = rand(0, 9); | |
$thirdPart = $numbers[$f] . $numbers[$s]; | |
} | |
return str_shuffle($firstPart . $secondPart . $thirdPart); | |
} | |
$sum = 0; | |
for ($i = 0; $i < 5000; $i++) { | |
ob_start(); | |
$start = microtime(); | |
echo generateUsername(); | |
$end = microtime(); | |
ob_end_clean(); | |
// | |
$time = ($end - $start); | |
$sum += $time; | |
} | |
echo 'Total avg execution time : ' . ($sum/5000) . ' seconds'; | |
?> |
<?php
function genUserName($length=6) {
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; // add other character you want
return substr(str_shuffle(str_repeat($pool, 6)), 0, $length);
}
?>
Easy to understand And Simple .... :P Hope It Works better For you Bro :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Total execution time : 0.00027600000000005 seconds
Total execution time : 0.000524 seconds
Total execution time : 0.00027699999999997 seconds
Total execution time : 0.000274 seconds
Total execution time : 0.00027500000000003 seconds