Visual Basic (Declaration) | |
---|---|
Public Shared Function NewGuid() As DbGuid |
C# | |
---|---|
public static DbGuid NewGuid() |
I say this is *mostly* sequential, because sometime after 2^24 (16m) guids are generated, the 25-bit incrementing number will 'roll over'. When this occurs and multiple guids are generated within the 4ms time window during this event, then it is possible that some may be out of sequence until the 4ms window passes. This anomaly in the sequencing should have no practical impact on performance. The collision chance within AppDomain are essentially non-existent due to the use of the incremented value. Across domains or processes the collision chance requires that Guids are generated within a 4ms window, happen to have the same 25-bit incremented value, and generate the same random 6-byte sequence while using cryptographic-strength PRNG. It's important to know that sequential guids like this drastically reduce the entropy size of the random value. Therefore DbGuid is more likely to produce duplicates than a regular fully-randomized guid. If you want to do the math on the collision probability of the 73-bit random value see the wikipedia article on the birthday paradox: http://en.wikipedia.org/wiki/Birthday_problem Keep in mind you must factor in the 4ms time interval with which DbGuids are timestamped. I'm not a math genius or anything, but generating a duplicate DbGuid is going to be more probable than generating a duplicate random guid, and less probable than being eaten by a shark.
Library/Library.Test/TestDbGuid.cs
C# | Copy Code |
---|---|
DbGuid testA = DbGuid.NewGuid(); TestEquality(testA, testA, true); TestEquality(testA, DbGuid.NewGuid(), false); TestEquality(testA, new DbGuid(Guid.NewGuid()), false); TestEquality(testA, testA.ToSqlGuid(), true); TestEquality(testA, testA.ToSqlGuid().ToSequenceGuid(), true); |
VB.NET | Copy Code |
---|---|
Dim testA As DbGuid = DbGuid.NewGuid() TestEquality(testA, testA, True) TestEquality(testA, DbGuid.NewGuid(), False) TestEquality(testA, New DbGuid(Guid.NewGuid()), False) TestEquality(testA, testA.ToSqlGuid(), True) TestEquality(testA, testA.ToSqlGuid().ToSequenceGuid(), True) |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7