Implementing

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                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#FieldBitsMSB = 0Value
1Name200–19Name encoding
2Random100 = 28 + 12 + 6020–47, 52–63, 68–127
3UUID version448–510x8
4UUID variant264–65MUST be 0b10
5TNID variant266–67MUST 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:

TNIDsChance of any collision
10⁹About 1 in 2.5 trillion
≈ 1.3 × 10¹⁵50%