Subroutine EnumerateValues generates premutations. It takes as a parameter the index of the next value that it needs to generate. For example, it might be ready to generate the third number in a permutation of five numbers.
The routine checks the index to see if it has already assigned all of the values. If it has assigned all of the values, it loops through the m_CurrentSolution array, which holds the values in their permuted order.
If some positions in the permutation are not yet filled in, the routine loops through the values and finds those that have not yet been used in the current solution. For each unused value, the routine adds the value to the solution, recursively calls itself to assign values for the remaining entries, and then removes the value from the current solution.