How Random is System.Guid.NewGuid()? (Take two)
Posted
by Vilx-
on Stack Overflow
See other posts from Stack Overflow
or by Vilx-
Published on 2010-04-12T11:14:45Z
Indexed on
2010/04/12
11:33 UTC
Read the original article
Hit count: 452
Before you start marking this as a duplicate, read me out. The other question has a (most likely) incorrect accepted answer.
I do not know how .NET generates its GUIDs, probably only Microsoft does, but there's a high chance it simply calls CoCreateGuid(). That function however is documented to be calling UuidCreate(). And the algorithms for creating an UUID are pretty well documented.
Long story short, be as it may, it seems that System.Guid.NewGuid()
indeed uses version 4 UUID generation algorithm, because all the GUIDs it generates matches the criteria (see for yourself, I tried a couple million GUIDs, they all matched).
In other words, these GUIDs are almost random, except for a few known bits.
This then again raises the question - how random IS this random? As every good little programmer knows, a pseudo-random number algorithm is only as random as its seed (aka entropy). So what is the seed for UuidCreate()
? How ofter is the PRNG re-seeded? Is it cryptographically strong, or can I expect the same GUIDs to start pouring out if two computers accidentally call System.Guid.NewGuid()
at the same time? And can the state of the PRNG be guessed if sufficiently many sequentially generated GUIDs are gathered?
© Stack Overflow or respective owner