using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
public static void Main()
for(int i = 0; i <= 50; i++)
Console.WriteLine(SequentialGuid.NewGuid());
public enum SequentialGuidType
public static class SequentialGuid
private static readonly RNGCryptoServiceProvider _rng = new RNGCryptoServiceProvider();
public static Guid NewGuid()
byte[] randomBytes = new byte[10];
_rng.GetBytes(randomBytes);
long timestamp = DateTime.UtcNow.Ticks / 10000L;
byte[] timestampBytes = BitConverter.GetBytes(timestamp);
if (BitConverter.IsLittleEndian)
Array.Reverse(timestampBytes);
byte[] guidBytes = new byte[16];
Buffer.BlockCopy(timestampBytes, 2, guidBytes, 0, 6);
Buffer.BlockCopy(randomBytes, 0, guidBytes, 6, 10);
Array.Reverse(guidBytes, 0, 4);
Array.Reverse(guidBytes, 4, 2);
return new Guid(guidBytes);