tags:

views:

118

answers:

3

Let's say I want to set a guid to be my application's assembly guid. As searched from internet, we can use (new Guid()).Next() to get a new unique value.

I cannot figure out how my guid is warranted to be unique against others? Please explain if you know how to.

+2  A: 

From http://en.wikipedia.org/wiki/Globally_unique_identifier:

Algorithm

In the OSF-specified algorithm for generating new (V1) GUIDs, the user's network card MAC address is used as a base for the last group of GUID digits, which means, for example, that a document can be tracked back to the computer that created it. This privacy hole was used when locating the creator of the Melissa worm[2]. Most of the other digits are based on the time while generating the GUID.

V1 GUIDs which contain a MAC address and time can be identified by the digit "1" in the first position of the third group of digits, for example {2f1e4fc0-81fd-11da-9156-00036a0f876a}.

V4 GUIDs use the later algorithm, which is a pseudo-random number. These have a "4" in the same position, for example {38a52be4-9352-453e-af97-5c3b448652f0}. More specifically, the 'data3' bit pattern would be 0001xxxxxxxxxxxx in the first case, and 0100xxxxxxxxxxxx in the second. Cryptanalysis of the WinAPI GUID generator shows that, since the sequence of V4 GUIDs is pseudo-random; given full knowledge of the internal state, it is possible to predict previous and subsequent values.[3].

Pieter
+4  A: 

It isnt, but the way it is generated and the way it is represented makes probability of generating two same GUIDs in this milenium almost zero.

See: http://stackoverflow.com/questions/1705008/simple-proof-that-guid-is-not-unique

Euphoric
+2  A: 

The only guarantee you have is that probability is on your side. 2^128 possible GUIDs and some cleverness in the creation process makes it very unlikely you will ever see a duplicate.

It seems V4 is the standard GUID on Windows now. If that one is purely based on a pseudo-random number generator, as Wikipedia seems to indicate, it's affected by the Birthday problem.

I've seen several examples using 128-bits to show that a duplicate is almost impossible. Those often miss two things. The Birthday problem and that a V4 GUID actually is 124 bits.

You need 1/2+sqrt(1/4-2*2^124*ln(0,5)) ≈ 5.4*10^18 GUIDs to reach a 50% chance of a duplicate. That is still a lot, but 50% may not be the deal you are looking for. Say you want it to be one in a million to get a duplicate, then you can have sqrt(2*2^124*ln(1/(1-0,000001))) ≈ 6,5*10^15 GUIDs. If you create a thousand GUIDs per second you could keep on doing that for almost 206667 years before reaching a one to a million risk of getting a duplicate. 6,52191054316287e15/(3600*24*365,25*1000) ≈ 206666,874006986

The chance of me getting all of those calculations correct →0.

Jonas Elfström