3

If I create a GUID using the constructor (say, Guid myGuid = new Guid("myguid")), is there a higher chance that it would collide with a GUIDs created with Guid.NewGuid() vs. two GUIDs both created with Guid.NewGuid()?

EDIT:

More specific question: Is there a greater chance to collide when comparing GUIDs based on a hash vs "Guid.NewGuid()?

Community
  • 1
  • 1
neverendingqs
  • 4,006
  • 3
  • 29
  • 57

3 Answers3

1

The real answer is it depends. Guid.NewGuid creates it based on several factors described here. If you take the string representation of creating it from NewGuid and you put that in the constructor, then the chance is the same as calling NewGuid twice.

That being said, not all GUIDs are created equal. Different systems have different ways of generating them, and they may not be as collision resistant as the .NET implementation. There is nothing to say that I couldn't create a string which could be parsed into GUIDs which isn't based on any rules. This GUID would have a much greater chance of a collision.

kemiller2002
  • 113,795
  • 27
  • 197
  • 251
0

If "myguid" value was created by legal GUID generator, then it's a equal chance.

0

With the newest GUID generator on Windows, which is pretty much a secure random number generator, the probability of guessing the next number and passing it to new Guid("myguid") is next to impossible.

It was different with older generators, when a GUID could be traced back to the hardware on which it has been created. Back then you could reverse-engineer the process of generating GUIDs, and try passing a colliding GUID on purpose.

Community
  • 1
  • 1
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523