Skip to content

Instantly share code, notes, and snippets.

@lyrixx
Created August 7, 2012 16:45
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 lyrixx/3287189 to your computer and use it in GitHub Desktop.
Save lyrixx/3287189 to your computer and use it in GitHub Desktop.
Generate a random string
<?php
$list = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9));
function getRandomString($length, $list) {
$str = array_fill(0, $length, null);
$str = array_map(function($item) use ($list) { return $list[array_rand($list)]; }, $str);
return join($str, '');
}
echo getRandomString(15, $list).PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment