How does C# generate GUIDs?

There is a really good article here that describes how GUIDs are generated, and in particular why a substring of a guid is not guarenteed to be unique.

Basiclly a GUID is generated using a combination of

  • The MAC address of the machine used to generate the GUID (so GUIDs generated on different machines are unique unless MAC addresses are re-used)
  • Timestamp (so GUIDs generated at different times on the same machine are unique)
  • Extra "emergency uniquifier bits" (these are used to ensure that GUIDs generated at nearly exactly the same time on the same machine are unique)
  • An identifier for the algorithm (so that GUIDs generated with a different algorithm are unique)

However, this is only 1 particular algorithm used for generating GUIDs (although I believe its the one used by the .Net framework), and is not the one used by the .Net framework


The algorithm is documented here as Globally unique identifier


Original question:

How the Guid is generating it's identifier?? How will be it's output if I use the following code Guid g = Guid.NewGuid();

Whether the output will be the combination of numbers and lettters or the numbers alone will be there???

A .Net System.Guid is just a 128-bit integer (16 bytes). Numbers and letters have nothing to do with it. You can use the ToString() method to see various "human-readable" versions of a Guid, which include numbers 0-9 and letters A-F (representing hex values), but that's all up to you how you want to output it.