Implementing

TNIDv1: 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 bits, the TNID variant field takes 2. Only TNIDs with the same name can collide. Birthday bound, one name:

TNIDs per day, for 20 yearsChance of any collision
100 thousand1 in 4.8 trillion
1 million1 in 48 billion
10 million1 in 480 million
100 million1 in 4.8 million
1 billion1 in 48,000
10 billion1 in 480