Definition
Random bits are the portion of a UUID filled by a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG). They are the primary source of uniqueness — the higher the count of random bits, the lower the probability that two independently generated UUIDs are identical.
UUID bit layout comparison
UUID v4 — 122 random bits:
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
← rand → ↑v4 ↑var ← rand →
All x bits are random (minus version + variant = 6 fixed bits)
UUID v7 — 74 random bits:
xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx
←48-bit ms→ ↑v7 ↑var←rand_a→←rand_b→
12 bits 62 bits random
CSPRNG sources per platform
| Platform | CSPRNG source |
|---|---|
| Node.js | crypto.randomFillSync() |
| Browser | crypto.getRandomValues() |
| Python | os.urandom() |
| Go | crypto/rand.Read() |
| Rust | getrandom crate |
| Java | SecureRandom |
All modern UUID libraries use CSPRNG sources. Never use Math.random() or equivalent non-cryptographic PRNGs for UUID generation — they produce predictable values with far fewer effective random bits. See CSPRNG.
Random bits and collision probability
The relationship between random bits b and the number of UUIDs n needed for a 50% collision probability follows the birthday problem approximation:
n ≈ √(2 · 2^b · ln 2)
| UUID version | Random bits | ~50% collision at |
|---|---|---|
| UUID v4 | 122 | 2.7 × 10¹⁸ values |
| UUID v7 | 74 | 6.1 × 10¹¹ values per millisecond |
| UUID v7 (with monotonic counter) | ~62 effective | Collisions eliminated within one generator |
At one billion UUIDs per second, UUID v4 would take 85 years to reach a 50% collision probability. UUID v7 provides weaker per-millisecond guarantees but the monotonic counter in RFC 9562-compliant implementations eliminates same-millisecond collisions within a single generator. See UUID Collision.
UUID v7 rand_a as monotonic counter
RFC 9562 §6.2 recommends Method 1 for same-millisecond ordering: use some of the rand_a bits as a monotonic counter that increments for each UUID generated within the same millisecond.
UUID v7 with monotonic counter (Method 1):
[48-bit ms][4-bit ver][12-bit counter][2-bit var][62-bit random]
↑ increments each UUID within same ms
The counter starts at a random value on each new millisecond, preserving sufficient randomness while guaranteeing strict ordering within a millisecond on a single generator instance. The 62-bit rand_b remains purely random.
Related terms
- CSPRNG — Cryptographically Secure Pseudo-Random Number Generator
- Entropy — randomness quality in UUID generation
- UUID Collision — probability and risk
- Monotonic Counter — within-millisecond UUID ordering
- UUID Security — entropy and token safety
Frequently asked questions
How many random bits does UUID v4 have?
UUID v4 has 122 random bits. Of the 128 total bits, 6 are fixed: 4 bits for the version field (0100) and 2 bits for the variant field (10). The remaining 122 bits are filled by a CSPRNG. This gives approximately 5.3 × 10³⁶ possible values.
How many random bits does UUID v7 have?
UUID v7 has 74 random bits: 12 bits in the rand_a field and 62 bits in the rand_b field. The remaining 54 bits are: 48-bit Unix millisecond timestamp, 4-bit version (0111), and 2-bit variant (10). Implementations may use some rand_a bits as a monotonic counter (per RFC 9562 §6.2), reducing effective randomness slightly but eliminating same-millisecond collisions entirely.
Is 74 random bits enough for UUID v7 to be collision-safe?
Yes, for any realistic workload. With 74 random bits, you need to generate more than 100 billion UUIDs in the same millisecond before a collision becomes likely. No production system approaches this rate. See UUID Collision for the birthday problem calculation.