Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create identical guids

Tags:

c#

.net

guid

Is it possible to create identical guids in one application

Guid id = Guid.NewGuid();
like image 892
Zlobaton Avatar asked Feb 28 '11 10:02

Zlobaton


2 Answers

Technically, yes. A created Guid looks for example like this:

26de36b7-76f5-4f17-8f9d-44eb429f151b

That means 32 chars that can be a letter (26 possibilities) or a digit (10 possibilities)

That means 36 posibilities per position for a total of 36^32 that is approx. 60 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000.

That means that if you create 2 000 000 000 000 000 000 000 000 000 000 000 000 000 Guids every millesecond (which is impossible), you will on average get the same guid created twice one time, and all the other guids will be unique.

So in practice. No ;)

like image 124
Øyvind Bråthen Avatar answered Sep 19 '22 14:09

Øyvind Bråthen


If you are asking if the risk of Guid.NewGuid() creating duplicate guids is high, then the answer is no. This is taken from Wikipedia:

The value of a GUID is represented as a 32-character hexadecimal string, such as {21EC2020-3AEA-1069-A2DD-08002B30309D}, and is usually stored as a 128-bit integer. The total number of unique keys is 2128 or 3.4×1038 — roughly 2 trillion per cubic millimeter of the entire volume of the Earth. This number is so large that the probability of the same number being generated twice is extremely small.

If you are asking us how to create two duplicate guids, then this is the answer:

Guid g1 = new Guid("21EC2020-3AEA-1069-A2DD-08002B30309D");
Guid g2 = new Guid("21EC2020-3AEA-1069-A2DD-08002B30309D");
like image 45
Andreas Vendel Avatar answered Sep 20 '22 14:09

Andreas Vendel