Last active
January 18, 2017 08:00
-
-
Save savvot/84a56f1439d23496dc6a069c2b18ce35 to your computer and use it in GitHub Desktop.
Short random hash \ string for UIDs,URIs, etc.
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 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