Skip to content

Instantly share code, notes, and snippets.

@ryansukale
Last active August 29, 2015 13:58
Show Gist options
  • Save ryansukale/9956955 to your computer and use it in GitHub Desktop.
Save ryansukale/9956955 to your computer and use it in GitHub Desktop.
//Inspired by https://github.com/klughammer/node-randomstring
function generateRandomCode($length){
$str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghiklmnopqrstuvwxyz';
$randomChar = $str[rand(0, strlen($str)-1)];
$length= ($length == null)? 32 : $length;
$randomArray = array();
for ($i = 0; $i < $length; $i++) {
array_push($randdomArray,$str[rand(0, strlen($str)-1)]);
}
$randomString = implode ( "" , $randdomArray );
return $randomString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment