Last active
August 29, 2015 14:12
-
-
Save Andrewpk/d1bdbae0c7c9286e5f33 to your computer and use it in GitHub Desktop.
PHP: pseudo-random string of defined length
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 | |
function randString($length, $charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-0123456789') | |
{ | |
$str = ''; | |
$count = strlen($charset) - 1; | |
while ($length--) { | |
$str .= $charset[mt_rand(0, $count)]; | |
} | |
return $str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment