Last active
August 29, 2015 14:10
-
-
Save acfreitas/3841fdbb4db1fe1b5433 to your computer and use it in GitHub Desktop.
String Random
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
/** | |
* @param int $size | |
* @return string | |
*/ | |
public function stringRandom($size) { | |
$validCharacters = utf8_decode("abcdefghijklmnopqrstuvxwzABCDFGHIJKLMNOPQRSTUVXWZ"); | |
$validCharNumber = strlen($validCharacters); | |
$string = ''; | |
while (strlen($string) < $size) { | |
$index = mt_rand(0, $validCharNumber - 1); | |
$string .= $validCharacters[$index]; | |
} | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment