开发者

C#, Best 64bit (long) Guid type generator for low collisions. Similar to Guid.NewGuid() but for 64 bits

I want to use a 64bit identifier similar to how Guids are used. Whats a good way of doing this? I want to keep collisions low.

public static unsafe long GetLongGuid()
{
   unch开发者_JS百科ecked
   {
      fixed (byte* ptr = Guid.NewGuid().ToByteArray())
         return *((long*)ptr) ^ *((long*)(ptr + 8));
   }
}

Should I just take the upper or lower bits instead?

Or is there a better native 64bit unique hash function that's good?


You can just use a random number generator instead, either System.Random or System.Security.Cryptography.RNGCryptoServiceProvider.

Exactly why you're using unsafe code here, if not for performance, is very unclear to me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜