Skip to content

Instantly share code, notes, and snippets.

@cdaven
Created May 21, 2013 12:20
Show Gist options
  • Save cdaven/5619397 to your computer and use it in GitHub Desktop.
Save cdaven/5619397 to your computer and use it in GitHub Desktop.
Generate a string of random characters
function generateRandomString($length = 10)
{
$alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
$alphabet_length = strlen($alphabet);
$randomChars = array();
for ($i = 0; $i < $length; $i++)
{
$randomChars[] = $alphabet[mt_rand(0, $alphabet_length - 1)];
}
return join('', $randomChars);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment