Comparing multiple const char's at once

I have an array of const char's that are randomly selected in a loop from a list and id like to compare every newly selected choice to be tested against all the others to make sure the same choice isn't given more than once, however the names are lengthy and, for example, using:

1
2
3
for (int x = 0; x<10;x++)//initial loop
while ((choice[x]== choice[x-1] || (choice[x] == choice[x-2]) || etc...)
//^given that I have 10 variables 


Would be messy and a painful sight. What would a more convinient way to check each choice?

Edit:It should be said that each choice would then be randomized again and then checked again, and that each newly selected choice is then immediantly used after this. It'll also be assumed that not all the choices have been made when this part runs(ergo choice[3] may not exist yet) as it is in a loop
Last edited on
You can do this:

-Make a selection
-Iterate over the already chosen chars
-If none are the same, choice is fine
-If one is the same, select a different char

OR (even better)

Mark each char as already been selected so it can't be selected again and then reset this selection at the appropriate time. You could do this (for example) by having an array of bools and each time a letter is selected, set the corresponding booleon arrat value to 1.

OR (even better)

Assuming your array is using unique chars, you can shuffle your array and just take the top n elements.

If your array is not using uniques, you can still use the shuffle, but just iterate over already selected choices and discard the selection if you already chose it.
Topic archived. No new replies allowed.