U
U
Uncle Bogdan2021-07-05 13:53:11
C++ / C#
Uncle Bogdan, 2021-07-05 13:53:11

How to check if there is the same element in the sheet, and if there is, then a new one?

The trick is that you need to check if the randomly selected character is already in the list of characters, then randomly select the character again and check again. How to make it infinite until such a character is not in the list?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Vodakov, 2021-07-05
@motkot

In pseudocode something like this:

uniqueCharacterSelected = false;
while not(uniqueCharacterSelected ) {
    newCharacter = SelectRandomCharacter();
    if (charactersList.find(newCharacter)=-1) {
        charactersList.add(newCharacter);
        uniqueCharacterSelected = true;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question