Skip to content

Instantly share code, notes, and snippets.

@ayende
Created April 16, 2020 07:22
Show Gist options
  • Save ayende/4a648a2d0708f30a2bcbc9b3a4717926 to your computer and use it in GitHub Desktop.
Save ayende/4a648a2d0708f30a2bcbc9b3a4717926 to your computer and use it in GitHub Desktop.
static void GenerateMatch(string key, ref string prefix)
{
var orig = GetShardId(key);
var tries = 0;
var sb = new StringBuilder(prefix).Append("-");
while (true)
{
for (int i = 0; i < 25; i++)
{
tries++;
sb.Length = prefix.Length + 1;
sb.Append(Convert.ToBase64String(BitConverter.GetBytes(tries)).Trim('=').ToLower());
if (GetShardId(sb.ToString()) == orig)
{
prefix = sb.ToString();
return;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment