Created
October 24, 2013 08:21
-
-
Save serapheem/7133207 to your computer and use it in GitHub Desktop.
PHP - Generator of random string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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