Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
420 views
in Technique[技术] by (71.8m points)

.net - How does C# generate GUIDs?

How are GUIDs generated in C#?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There's a really good article on Raymond Chen's blog that describes how GUIDs are generated, and in particular why a substring of a guid is not guaranteed to be unique.

Basically, a 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 it's the one used by the .NET framework), and is not the one used by the .NET framework.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...