SShebly
SShebly

Reputation: 2073

how a GUID is generated to be unique and is it always unique?

the simple idea we have about GUID is that it's unique, but how GUIDs are generated ? could we generate two identical GUIDs based on the same generation methods used.

Upvotes: 3

Views: 613

Answers (2)

Michael
Michael

Reputation: 620

GUIDS aren't guaranteed to be unique, however they are said to be "statistically unique" since the probability of creating the same guid twice is statistically insignificant. For all intensive purposes, you'll be safe to assume that any GUID you create (properly) is unique.

As to how GUIDs are generated, they use different algorithms depending on the type of GUID. For instance, SQL Server's "uniqueidentifier" datatype uses a V4 GUID which is based on a pseudorandom data generator whereas other versions of GUIDs can be based on hash functions or a combination of MAC adress and time.

Is it possible to generate a duplicate GUID? Well of course, but the chances of it happening are just statistically insignificant.

Trust the GUID. It exists to make your life easier :)

Upvotes: 2

Victor Sorokin
Victor Sorokin

Reputation: 12006

Yes, we can generate same GUID twice, but with probability close to zero enough to make this event practically impossible.

Upvotes: 1

Related Questions