Created
February 22, 2017 15:21
-
-
Save bugshake/bc85e32959a74b7fb6ab451356857096 to your computer and use it in GitHub Desktop.
Translate a unique ID into something human readable/recognizable/discernable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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