Cryptographically Random UUID v4 (122 Bits of Entropy)
UUID Version 4 (RFC 9562 / RFC 4122) is the industry standard for stateless, non-guessable unique identifiers, API correlation tokens, session keys, and object storage filenames. Out of 128 total bits, 6 bits are reserved for the version (0100 = 4) and variant (10), leaving 122 bits of pure cryptographic randomness.
With 5.3 × 10³⁶ possible values, you would need to generate 1 billion UUIDv4 identifiers every second for 85 years to reach a 50% probability of a single collision under the birthday paradox.
- Zero Timestamp or MAC Leakage: Unlike UUIDv1 or UUIDv7, UUIDv4 reveals zero metadata about when or where the identifier was created.
- Hardware-Seeded Web Crypto API: Generated 100% client-side via crypto.getRandomValues() with zero server logging.
RFC 9562 Bit Masking & Wire Formatting Options
To construct a compliant RFC 9562 UUIDv4 from 16 random bytes, the generator masks byte 6 with (byte[6] & 0x0f) | 0x40 to set the 4-bit version nibble to 0100 (version 4), and masks byte 8 with (byte[8] & 0x3f) | 0x80 to set the 2-bit variant field to 10.
Depending on your target runtime—such as PostgreSQL uuid columns, Microsoft .NET Guid structs, AWS S3 object keys, or compact 32-character hex tokens—you can toggle uppercase letters and strip hyphens in real time before copying or downloading your bulk batch.
- Canonical 8-4-4-4-12 Format (36 Characters): Standard hyphenated lowercase representation accepted by SQL databases, GraphQL scalars, and OpenAPI schemas.
- Compact 32-Hex & Uppercase GUID Modes: Strip hyphens to save 4 bytes per string in high-volume JSON payloads, or switch to uppercase for Windows Registry and COM/DCOM GUIDs.
Practical Real-World Use Cases
Choose UUIDv4 whenever unguessable entropy and zero timestamp disclosure matter more than chronological B-Tree ordering:
- Idempotency-Key & X-Request-ID HTTP Headers: Attach a fresh UUIDv4 to payment retries and distributed trace headers so upstream gateways deduplicate requests without leaking creation timestamps.
- Unlisted Share Links & Multi-Tenant Object Storage Keys: Prefix S3/GCS upload paths and capability URLs with random UUIDv4 directories so external users cannot enumerate adjacent files or infer upload volume.
- .NET / COM Interface GUIDs & Game Asset Identifiers: Export uppercase GUIDs for C# [Guid("...")] attributes, Windows Installer ProductCodes, Unity/Unreal asset metadata, and mock test datasets.
Frequently Asked Questions
How many random bits are in a UUID v4?
A UUID v4 contains 122 cryptographically random bits out of 128 total bits (4 bits identify version 4 and 2 bits identify the RFC 9562 variant), yielding 2^122 (5.3 × 10^36) unique combinations.
When should I choose UUID v4 over UUID v7?
Choose UUID v4 whenever creation timestamps must remain private (such as public resource URLs, capability tokens, password reset links, or API keys) so external users cannot infer creation time or enumeration rates.