Skip to content

Instantly share code, notes, and snippets.

@savvot
Last active January 18, 2017 08:00
Show Gist options
  • Save savvot/84a56f1439d23496dc6a069c2b18ce35 to your computer and use it in GitHub Desktop.
Save savvot/84a56f1439d23496dc6a069c2b18ce35 to your computer and use it in GitHub Desktop.
Short random hash \ string for UIDs,URIs, etc.
<?php
function randuid($len = 8)
{
$uid = '';
do {
$uid .= base_convert(random_int(PHP_INT_MIN, PHP_INT_MAX), 10, 36);
$uid .= strtoupper(base_convert(random_int(PHP_INT_MIN, PHP_INT_MAX), 10, 36));
} while(strlen($uid) < $len * 2);
$uid = substr(str_shuffle($uid), 0, $len);
return $uid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment