Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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