Is a GUID unique 100% of the time?

前端 未结 22 2560
孤独总比滥情好
孤独总比滥情好 2020-11-22 01:31

Is a GUID unique 100% of the time?

Will it stay unique over multiple threads?

22条回答
  •  孤街浪徒
    2020-11-22 02:24

    Theoretically, no, they are not unique. It's possible to generate an identical guid over and over. However, the chances of it happening are so low that you can assume they are unique.

    I've read before that the chances are so low that you really should stress about something else--like your server spontaneously combusting or other bugs in your code. That is, assume it's unique and don't build in any code to "catch" duplicates--spend your time on something more likely to happen (i.e. anything else).

    I made an attempt to describe the usefulness of GUIDs to my blog audience (non-technical family memebers). From there (via Wikipedia), the odds of generating a duplicate GUID:

    • 1 in 2^128
    • 1 in 340 undecillion (don’t worry, undecillion is not on the quiz)
    • 1 in 3.4 × 10^38
    • 1 in 340,000,000,000,000,000,000,000,000,000,000,000,000

提交回复
热议问题