Skip to content

Instantly share code, notes, and snippets.

@gsouf
Created June 8, 2015 09:33
Show Gist options
  • Save gsouf/01b7ce80f030d5757940 to your computer and use it in GitHub Desktop.
Save gsouf/01b7ce80f030d5757940 to your computer and use it in GitHub Desktop.
generate random alphanum codes
<?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