How does C# generate GUIDs?

后端 未结 8 1255
北荒
北荒 2020-12-17 07:38

How are GUIDs generated in C#?

8条回答
  •  抹茶落季
    2020-12-17 08:21

    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

提交回复
热议问题