Skip to content

Instantly share code, notes, and snippets.

@serapheem
Created October 24, 2013 08:21
Show Gist options
  • Save serapheem/7133207 to your computer and use it in GitHub Desktop.
Save serapheem/7133207 to your computer and use it in GitHub Desktop.
PHP - Generator of random string
<?php
/**
* Generates the random string specified length
* @param int $length
*
* @return string
*/
protected function getRandomString($length)
{
$salt = array_merge(range('a', 'z'), range(0, 9));
$maxIndex = count($salt) - 1;
$result = '';
for ($i = 0; $i < $length; $i++) {
$index = mt_rand(0, $maxIndex);
$result .= $salt[$index];
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment