Skip to content

Instantly share code, notes, and snippets.

@bugshake
Created February 22, 2017 15:21
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bugshake/bc85e32959a74b7fb6ab451356857096 to your computer and use it in GitHub Desktop.
Save bugshake/bc85e32959a74b7fb6ab451356857096 to your computer and use it in GitHub Desktop.
Translate a unique ID into something human readable/recognizable/discernable
public static class ReadableID
{
static readonly string[] syllables = new string[256];
public static void initOnce()
{
string[] consonants = new string[] { "b", "br", "c", "ch", "d", "f", "fr", "g", "h", "j", "k", "kn", "l", "m", "n", "p", "pr", "qu", "r", "s", "st", "sl", "sc", "t", "tr", "v", "w", "x", "z" };
string[] vowels = new string[] { "a", "e", "i", "o", "u", "y", "ae", "ee", "ea", "ai" };
for (int i = 0; i < syllables.Length; ++i)
{
syllables[i] = consonants[i % consonants.Length] + vowels[i / consonants.Length];
}
}
public static string makeReadable(uint ID)
{
// NOTE: hash ID through something like Deadbeef32 (http://stackoverflow.com/a/694312)
// to get more diverse words
return string.Format("{0}{1}{2}{3}",
syllables[ID >> 24],
syllables[(ID >> 16) & 0xFF],
syllables[(ID >> 8) & 0xFF],
syllables[ID & 0xFF]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment