Variant 1: random
View this section in the spec ↗Like UUIDv4: all 100 payload bits random.
Layout
1111.1111.1111.1111.1111.2222.2222.2222-
2222.2222.2222.2222-
3333.2222.2222.2222-
4455.2222.2222.2222-
2222.2222.2222.2222.2222.2222.2222.2222.2222.2222.2222.2222 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| name | random |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| random | ver | random |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|var| tv| random |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| random |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| # | Field | Bits | MSB = 0 | Value |
|---|---|---|---|---|
| 1 | Name | 20 | 0–19 | Name encoding |
| 2 | Random | 100 = 28 + 12 + 60 | 20–47, 52–63, 68–127 | |
| 3 | UUID version | 4 | 48–51 | 0x8 |
| 4 | UUID variant | 2 | 64–65 | MUST be 0b10 |
| 5 | TNID variant | 2 | 66–67 | MUST be 0b01 |
The spec names no random source. Use a CSPRNG wherever guessing a TNID could cause harm.
Goals and non-goals
- Goals: maximum entropy within the UUID and TNID specs; reasonable for 99% of use cases (low chance of collision, low stakes if one happens).
- Non-goal: maximum entropy at the expense of TNID's other goals.
Caveats
Fewer random bits than UUIDv4
100 random bits vs UUIDv4's 122: the name takes 20, the TNID variant 2. Only TNIDs with the same name can collide. Birthday bound, one name:
| TNIDs | Chance of any collision |
|---|---|
| 10⁹ | About 1 in 2.5 trillion |
| ≈ 1.3 × 10¹⁵ | 50% |