Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Random is System.Guid.NewGuid()?

Tags:

.net

guid

random

I know this may sounds like a pointless question, but hear me out...

I basically want to know if I can trust the GUID to generate a value which will be unique 100% of the time and impossible to predict.

I'm basically rolling my on login system for a website and want to know if the GUID is secure enough for session cookies.

Any background on how the GUID is generated would be much appreciated in evaluating the answers.

Thanks for the links to duplicate questions, however, my question is specific to the .Net framework.

like image 977
GateKiller Avatar asked Jan 21 '09 22:01

GateKiller


People also ask

How random is a GUID?

How unique is a GUID? 128-bits is big enough and the generation algorithm is unique enough that if 1,000,000,000 GUIDs per second were generated for 1 year the probability of a duplicate would be only 50%. Or if every human on Earth generated 600,000,000 GUIDs there would only be a 50% probability of a duplicate.

Is GUID truly random?

Definitely not random. Similarly, the person who wanted to use a GUID for password generation would find that the passwords are totally predictable if you know what time the GUID was generated and which computer generated the GUID (which you can get by looking at the final six bytes from some other password-GUID).

Is GUID NewGuid unique?

Multiple threads allocating new guids will get unique values, but you should get that the function you are calling is thread safe.

What does GUID NewGuid () do?

Guid. NewGuid() creates an empty Guid object, initializes it by calling CoCreateGuid and returns the object.


2 Answers

Here's an excellent breakdown by Raymond Chen

like image 139
John Sheehan Avatar answered Sep 28 '22 01:09

John Sheehan


No fixed-length value can ever guarantee to be 100% unique (just call it enough times, give or take the universe ending ;-p) - but it can be very, very, very unlikely to duplicate.

like image 27
Marc Gravell Avatar answered Sep 28 '22 00:09

Marc Gravell