Not really.
How much of "not really" depends on the GUID type, and on your understanding of probabilities.
A "real" GUID, version 1, the value is guaranteed to be unique. It's formed by combining the MAC address of your network card (unique, unless you change it manually) and a timestamp.
A pseudo-random GUID, version 4, is not guaranteed to be unique, but it is extremely unlikely to get a collision anyway. You have 122 bits to work with, and 2^122
is a very big number. Like, really big. Using Guid.NewGuid()
is fine - although it should be noted that the random numbers used to generate the GUID are not crypto-random.
Of course, different implementations of GUIDv4 will have markedly different entropies. If you just use Random
to generate the numbers, you're nowhere near the 122-bit maximum. So don't think you can just write your own code to generate GUIDs, most of such attempts and with nothing more unique than just Random.Next()
- by far not good enough for a primary key in a database.
Note that GUIDs are commonly used in scenarios like replication, which are completely built on two generated GUIDs being unique.