Created
June 8, 2015 09:33
-
-
Save gsouf/01b7ce80f030d5757940 to your computer and use it in GitHub Desktop.
generate random alphanum codes
This file contains hidden or 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 | |
$codes = array(); | |
function generateCode(){ | |
global $codes; | |
$chars = "azertyupqsdfghjklmwxcvbn23456789"; | |
$charsCount = strlen($chars) - 1; | |
$countCode = 8; | |
$code = ""; | |
for($i = 0 ; $i < $countCode ; $i++){ | |
$rdm = rand(0,$charsCount); | |
$code .= $chars{$rdm}; | |
} | |
if(isset($codes[$code])){ | |
generateCode(); | |
}else{ | |
$codes[$code] = 1; | |
} | |
} | |
$totalCodes = 5000; | |
for($i = 0 ; $i < $totalCodes ; $i++){ | |
generateCode(); | |
} | |
foreach($codes as $k=>$v){ | |
echo($k) . PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment