Created
September 3, 2017 08:50
-
-
Save jianingy/032a60c79cef0b31ecae3fcd4e8a5cf0 to your computer and use it in GitHub Desktop.
simple 96 bits uuid
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 uuid32() { | |
return sprintf("%08X", rand(0, pow(2, 32))); | |
} | |
function uuid96() { | |
$uuid = uuid32() . uuid32() . uuid32(); | |
$serial = ""; | |
foreach (str_split($uuid, 2) as $b) { | |
$serial .= chr(hexdec($b)); | |
} | |
return $serial; | |
} | |
print base64_encode(uuid96()) . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment