Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a version 1 Guid in .NET?

Tags:

.net

guid

As I understand it, Version 1 Guids that relied on timestamps and MAC address, were replaced by Version 4 - more random - in Windows 2000 or thereabouts.

What's the easiest way to generate a Version 1 guid from .Net, if I prefer it to a version 4?

(I do want the timestamp and (almost) unique machine id to be extractable. I do control the entire environment - I'm ok with privacy/any loss of absolute randomness)

Thanks.

like image 515
Nik Avatar asked Feb 23 '12 10:02

Nik


1 Answers

P/Invoke UuidCreateSequential - it returns type 1 guids:

For security reasons, UuidCreate was modified so that it no longer uses a machine's MAC address to generate UUIDs. UuidCreateSequential was introduced to allow creation of UUIDs using the MAC address of a machine's Ethernet card.

like image 171
Damien_The_Unbeliever Avatar answered Nov 15 '22 00:11

Damien_The_Unbeliever