Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could this cause multiple identical GUIDs?

Tags:

c#

guid

collision

As GUID generation is time-dependent, if System.Guid.NewGuid() is called multiple times at the exact same instant on different threads, could it return identical GUIDs?

like image 465
billybum Avatar asked Feb 04 '23 04:02

billybum


2 Answers

On Windows, GUIDs (UUIDs) are created from a cryptographic random number generator with UuidCreate. They are version 4 UUIDs in terms of RFC 4122. No timestamps or ethernet cards are involved, unless you're using old school version 1 GUIDs created with UuidCreateSequential.

See also How Random is System.Guid.NewGuid()? (Take two)

like image 70
George V. Reilly Avatar answered Feb 07 '23 10:02

George V. Reilly


No, there is a serial number inside it that changes for each call, so multiple simultaneous calls on different threads on the same system will not create duplicate Guids.

That does not mean that there is a visible part of the Guid that you can see increments for each call.

like image 41
Lasse V. Karlsen Avatar answered Feb 07 '23 10:02

Lasse V. Karlsen