Created
October 20, 2016 14:57
-
-
Save Kobzol/cb4d18bc54af686088216cc7c62dd79a to your computer and use it in GitHub Desktop.
Generate word at a given index
This file contains 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
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