Which version should you use?
If the identifier becomes a primary key, time-ordered variants are usually better: they cluster inserts at the end of the index instead of scattering them across pages. If the identifier is a public token, v4's larger random space is preferable.
| Type | Sortable | Random bits | Best for |
|---|---|---|---|
| UUID v4 | No | 122 | General-purpose IDs where order does not matter |
| UUID v7 | Yes (time) | 74 | Database keys, event IDs, log correlation |
| ULID | Yes (time) | 80 | Sortable IDs with a compact 26-character form |
| UUID v1 | Yes (time + node) | — | Legacy systems; leaks MAC address in some implementations |
How generation works in the browser
v4 uses crypto.getRandomValues to fill 122 random bits and sets the version and variant nibbles. v7 combines a 48-bit millisecond timestamp with 74 random bits, and sets the same version/variant markers. ULID encodes a 48-bit timestamp and 80 random bits in Crockford's base32.
None of these call a server. The identifier exists only in your browser until you copy it, which matters when the ID is a secret or a capability token.
Browser randomness is not a substitute for cryptographic key generation. For secrets, encryption keys or session tokens, use the platform's cryptography API.
Collision math
v4 has 122 random bits: roughly 5.3 × 10^36 possible values. You would need about 2.6 × 10^18 IDs before a 50% collision chance (birthday bound), far beyond any practical table. v7 trades random bits for time order, but its 74 random bits inside the same millisecond still give about 1.9 × 10^22 combinations.