Skip to content

Instantly share code, notes, and snippets.

@lazyjerry
Created August 6, 2020 15:56
Show Gist options
  • Save lazyjerry/e3d890d2bd68c450b71f4e1b1f3a7063 to your computer and use it in GitHub Desktop.
Save lazyjerry/e3d890d2bd68c450b71f4e1b1f3a7063 to your computer and use it in GitHub Desktop.
private function random_string($length = 5, $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
if (!is_int($length) || $length < 0) {
return false;
}
$characters_length = strlen($characters) - 1;
$string = '';
for ($i = 0; $i < $length; $i++) {
$string .= $characters[mt_rand(0, $characters_length)];
}
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment