Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many times can you randomly generate a GUID before you risk duplicates? (.NET)

Mathematically I suppose it's possible that even two random GUIDs generated using the built in method in the .NET framework are identical, but roughly how likely are they to clash if you generate hundreds or thousands?

If you generated one for every copy of Windows in the world, would they clash?

The reason I ask is because I have a program that creates a lot of objects, and destroys some too, and I am wondering about the likelihood of any of those objects (including the destroyed ones) having identical GUIDs.

like image 593
NibblyPig Avatar asked Apr 11 '10 17:04

NibblyPig


1 Answers

There are ~3E38 possible GUID values. But the Birthday Paradox cuts the 50/50 odds to producing a duplicate GUID to ~1E19. While still an enormous number, comparing quite favorably to the odds that your machine will be destroyed by a meteor impact first, the system clock is used to ensure no duplicates can occur.

Many large and mission critical dbase apps use a GUID as the primary key in a table. Don't hesitate to follow their lead.

like image 57
Hans Passant Avatar answered Sep 28 '22 16:09

Hans Passant