Skip to content

Instantly share code, notes, and snippets.

@shiny
Created March 26, 2015 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiny/3f1afdbfcc465db1dd5f to your computer and use it in GitHub Desktop.
Save shiny/3f1afdbfcc465db1dd5f to your computer and use it in GitHub Desktop.
example.php
<?php
function createStr($num = 700, $len = 6){
if($num===0){
return [];
}
$numbers = range(0, 9);
$letters = range('a', 'z');
$uppers = range('A', 'Z');
$elements = array_merge($numbers, $letters, $uppers);
$strings = [];
for($i = 0; $i < $num; $i++){
$str = '';
$keys = array_rand($elements, $len);
foreach($keys as $index){
$str .= $elements[$index];
}
$strings[] = $str;
}
$strings = array_unique($strings);
$count = count($strings);
while($count < $num){
$append = createStr($num - $count, $len);
$strings = array_merge($strings, $append);
$count = count($strings);
}
return $strings;
}
print_r(createStr(51630));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment