Skip to content

Instantly share code, notes, and snippets.

@Kobzol
Created October 20, 2016 14:57
Show Gist options
  • Save Kobzol/cb4d18bc54af686088216cc7c62dd79a to your computer and use it in GitHub Desktop.
Save Kobzol/cb4d18bc54af686088216cc7c62dd79a to your computer and use it in GitHub Desktop.
Generate word at a given index
void generate(int index, int wordSize, int alphabetSize, char* result, char base = 0)
{
for (int i = wordSize - 1; i >= 0; i--)
{
int toSkip = std::pow(alphabetSize, i);
char c = index / toSkip;
result[wordSize - i - 1] = base + c;
index = index % toSkip;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment