问题
Researching the subject yesterday, I found several interesting questions (such as this one) on how GUIDs are ultimately generated. In brief; it seems that Guid.NewGuid();
calls CoCreateGuid
in the COM, which in turn calls UuidCreate
in the Windows RPC (docs here and here).
I found myself wondering; How does this work when the OS is not Windows, such as might be the case with .NET Core, and does this affect the 'version' algorithm used to generate the GUID (which I understand is Version 4 on Windows)?
回答1:
On non-windows machines, .NET Core will use either uuid_create on BSD (which is "version 1") or libuuid's uuid_generate_random function on macOS and linux ("version 4").
The implementation for the replacement CoCreateGuid
function can be found in CoreCLR's source code on GitHub.
来源:https://stackoverflow.com/questions/44924804/guid-newguid-behind-the-scenes-in-net-core