Generate UUID
What is a UUID?
UUID (Universally Unique Identifier) is a 128-bit label used to identify information in computer systems. They follow RFC 4122 with several versions, each with different generation methods.
UUID Versions Explained
UUID v1 (Timestamp)
xxxxxxxx-xxxx-1xxx-xxxx-xxxxxxxxxxxx
Embeds timestamp and MAC address. Sortable but exposes node information.
UUID v4 (Random)
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
Most common version. Random generation means negligible collision probability.
UUID v7 (Unix Epoch)
xxxxxxxx-xxxx-7xxx-xxxx-xxxxxxxxxxxx
Combines Unix timestamp with randomness. Sortable and privacy-preserving.
When to Use Each UUID Type
- v4: General-purpose identifiers for databases, sessions, and any case where privacy matters.
- v1: Legacy systems needing chronological ordering. Use cautiously due to MAC exposure.
- v7: Modern apps needing time-sortable IDs without v1's privacy issues. Ideal for distributed systems.
Security Considerations
UUID v4 is not cryptographically secure. Do not use standard UUIDs for security tokens or cryptographic keys. Use dedicated CSPRNG libraries instead.