Skip to content
Browse files

added clockSequence back in using the Environment.TickCount to close …

…out issue #66
  • Loading branch information...
1 parent 0547280 commit 794d97f2cedc6990f1781e8094920e18db067817 @nberardi nberardi committed Sep 21, 2012
Showing with 9 additions and 6 deletions.
  1. +9 −6 src/GuidGenerator.cs
View
15 src/GuidGenerator.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics;
namespace FluentCassandra
{
@@ -30,16 +31,13 @@ public static partial class GuidGenerator
private static readonly DateTimeOffset GregorianCalendarStart = new DateTimeOffset(1582, 10, 15, 0, 0, 0, TimeSpan.Zero);
// random clock sequence and node
- public static byte[] DefaultClockSequence { get; set; }
public static byte[] DefaultNode { get; set; }
static GuidGenerator()
{
- DefaultClockSequence = new byte[2];
DefaultNode = new byte[6];
var random = new Random();
- random.NextBytes(DefaultClockSequence);
random.NextBytes(DefaultNode);
}
@@ -49,6 +47,11 @@ public static GuidVersion GetVersion(this Guid guid)
return (GuidVersion)((bytes[VersionByte] & 0xFF) >> VersionByteShift);
}
+ private static byte[] ClockSequence
+ {
+ get { return BitConverter.GetBytes(Convert.ToInt16(Environment.TickCount % Int16.MaxValue)); }
+ }
+
public static DateTimeOffset GetDateTimeOffset(Guid guid)
{
byte[] bytes = guid.ToByteArray();
@@ -83,17 +86,17 @@ public static DateTime GetUtcDateTime(Guid guid)
public static Guid GenerateTimeBasedGuid()
{
- return GenerateTimeBasedGuid(DateTimePrecise.UtcNowOffset, DefaultClockSequence, DefaultNode);
+ return GenerateTimeBasedGuid(DateTimePrecise.UtcNowOffset, ClockSequence, DefaultNode);
}
public static Guid GenerateTimeBasedGuid(DateTime dateTime)
{
- return GenerateTimeBasedGuid(dateTime, DefaultClockSequence, DefaultNode);
+ return GenerateTimeBasedGuid(dateTime, ClockSequence, DefaultNode);
}
public static Guid GenerateTimeBasedGuid(DateTimeOffset dateTime)
{
- return GenerateTimeBasedGuid(dateTime, DefaultClockSequence, DefaultNode);
+ return GenerateTimeBasedGuid(dateTime, ClockSequence, DefaultNode);
}
public static Guid GenerateTimeBasedGuid(DateTime dateTime, byte[] clockSequence, byte[] node)

0 comments on commit 794d97f

Please sign in to comment.
Something went wrong with that request. Please try again.