Universally Unique Identifier Version 9
The v9 UUID supports both sequential (time-based) and non-sequential (random) UUIDs with an optional prefix of up to four bytes, an optional checksum, and sufficient randomness to avoid collisions. It uses the UNIX timestamp for sequential UUIDs and CRC-8 for checksums. A version digit can be added if desired, but is omitted by default.
How it works.
The best way to explain the v9 UUID is with examples of its features. Even with all features enabled there are still five bytes of randomness (1610 possible values per millisecond).
Non-Sequential
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
x = random
Non-Sequential + Prefix
yyyyyyyy-xxxx-xxxx-xxxx-xxxxxxxxxxxx
x = random, y = prefix (optional)
Sequential
zzzzzzzz-zzzx-xxxx-xxxx-xxxxxxxxxxxx
x = random, z = timestamp (optional)
Sequential + Prefix + Checksum
yyyyyyyy-zzzz-zzzz-zzzx-xxxxxxxxxxcc
x = random, y = prefix (optional), z = timestamp (optional), c = checksum (optional)
Sequential + Prefix + Checksum + Version
yyyyyyyy-zzzz-9zzz-zzzz-xxxxxxxxxxcc
x = random, y = prefix (optional), z = timestamp (optional), c = checksum (optional), 9 = version (optional)
Assembly Instructions
- Start with an empty string and append a hexadecimal prefix of up to 8 characters if desired.
- For an ordered ID, convert the Unix timestamp into hexadecimal and append it to the string (time granularity is not specified and depends on project requirements and system capabilities).
- Pad the end of the string with randomly-selected hexadecimal characters to achieve a string length of 32 (unless a checksum is desired, in which case the string should be 30 characters).
- Versioning is not required, but if desired insert a "9" as the 13th character and use one fewer random character at the end. To simulate a legacy UUID version instead, insert the relevant legacy version digit as the 13th character ("1" for ordered and "4" for unordered), a randomly selected "a", "b", "8", or "9" as the 17th character, and use two fewer random characters at the end.
- If a checksum is desired, compute a two-hexadecimal-digit CRC-8 checksum of the string and append it to the end.
- Finally, insert four dashes at positions 9, 14, 19, and 24. The resulting string should be 36 characters long, lowercase, and match the regular expression "/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/".
How to use it.
Zero-dependency implementations are available in JavaScript, Python, Go, PHP, and Ruby. For language requests or to suggest an improvement to an implementation please contact us.
We're here to help.
If you have comments, questions, or suggestions, or are interested in learning how to leverage the features of v9 UUIDs in your organization, please use this form to get in touch.