Skip to content

Instantly share code, notes, and snippets.

@montyanderson
Last active August 15, 2017 13:32
Show Gist options
  • Save montyanderson/8d6c24d44f28f845e780b9731a02dfd2 to your computer and use it in GitHub Desktop.
Save montyanderson/8d6c24d44f28f845e780b9731a02dfd2 to your computer and use it in GitHub Desktop.
<?php
function randomId($length) {
$chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$max = strlen($chars) - 1;
$id = "";
for($i = 0; $i < $length; $i++) {
$id .= $chars[random_int(0, $max)];
}
return $id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment