Skip to content

Instantly share code, notes, and snippets.

@minhhungit
Forked from ayende/GetShardId.cs
Created April 23, 2020 23:50
Show Gist options
  • Save minhhungit/65e9a903305c36bdbc21d8ac1c297b97 to your computer and use it in GitHub Desktop.
Save minhhungit/65e9a903305c36bdbc21d8ac1c297b97 to your computer and use it in GitHub Desktop.
static ushort GetShardId(string key)
{
using var md5 = MD5.Create();
{
var hash = md5.ComputeHash(Encoding.UTF8.GetBytes(key));
var integer = BigInteger.Abs(new BigInteger(hash));
return (ushort)(integer % ushort.MaxValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment