7

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)?

Parrybird
  • 800
  • 11
  • 18
  • 4
    You check how Mono does it here: https://github.com/mono/mono/blob/master/mcs/class/corlib/System/Guid.cs – Magnus Jul 05 '17 at 11:25

1 Answers1

13

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.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • `nm libcoreclr.dylib | grep uuid` (macOS) says that it calls `uuid_generate_random`; which is a v4 GUID. `uuid_create` must be a macro somewhere on that platform. – bartonjs Jul 05 '17 at 15:27
  • sry yes macOS also uses the other function, I assumed it aligned to BSD here. A quick check tells me macOS indeed ships a `` header with `uuid_generate_random` being provided by `libSystem.B.dylib` – Martin Ullrich Jul 05 '17 at 15:42