Possible Duplicate:
Is a GUID unique 100% of the time?
Simple proof that GUID is not unique
In MSDN you can read:
The chance that the value of the new Guid will be all zeros or equal to any other Guid is very low.
Say that you have an method that will create a file every second, and you use the method Guid.NewGuid()
for filename, is it possible to get the same Guid then? Or will the local computer keep track in some way? How low is the chance ?
Guid. NewGuid() creates an empty Guid object, initializes it by calling CoCreateGuid and returns the object.
Multiple threads allocating new guids will get unique values, but you should get that the function you are calling is thread safe.
Technically they are 128-bit unique reference numbers used in computing which are highly unlikely to repeat when generated despite there being no central GUID authority to ensure uniqueness.
You are concerned with concurrency: fortunately, the NewGuid method is thread-safe, which means it either locks or utilizes a thread-static random number generator for its purposes.
The chances of getting two identical guids are astronomically slim even if you are generating guids as fast as you can. (Generating, say, thousands of guids per second for the sole purpose of finding a duplicate.)
Of course, if you want my opinion, I do believe that there will be a time, in a couple of thousand years from now, when we will be colonizing the galaxy, our population will be in the trillions, the number of individual computers embedded everywhere will number in the gazillions, and every single one of those computers will be generating GUIDs at a rate which is unthinkable today, when we will start running into trouble with duplicate guids popping up every once in a while in distant areas of the galaxy, and then it will be like 640k of memory all over again, DLL hell all over again, two-digit-year millenium bug all over again, all of them combined.
The thing with GUIDs is that we don't want them to be huge, because then they would be wasteful, so someone had to come up with a number of bits that is small enough to not be too wasteful and yet large enough to give a reasonable guarantee against collisions. So, it is a technological compromise. In our century 128 bits seem to be a good compromise, but with almost mathematical certainty there will be another century when this compromise will not be so good anymore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With