How short can a GUID be?

前端 未结 6 1804
离开以前
离开以前 2021-02-07 04:01

I know the standard GUIDs. Can they be made shorter? What is the theory behind it?

6条回答
  •  庸人自扰
    2021-02-07 04:53

    The shorter "allegedly globally unique" IDs are, the higher the chance of a collision when many of them are more-or-less-randomly generated -- and, that chance's probably higher than you'd think, due to the "birthday paradox"... see http://betterexplained.com/articles/understanding-the-birthday-paradox/ . As a (very approximate but useful) rule of thumb, the chance is non-negligible if (among N possible UIDs) you assign sqrt(N) or so. A 128-bit ID is therefore pretty safe from accidental collision, even for many billions of IDs; but if you were to shorten it to, say, 32 bits, you'd have substantial risk of collisions even for just a few tens of thousands of IDs.

提交回复
热议问题