Attempting to get item 10 of a list of length 9 error

I don't get this error all the time when I try to run my code. Usually, it works but sometimes this error pops up. Where is the problem, what is causing it and how can I fix it?

Try making this:


into this:


If that only ever allows 9, then change 10 to 11.

The thing is, it doesn't always happen, it's random. I need the if statement to say more than 10, not more than or equal to 10 because 10 is the maximum amount of names, not 9 and when the amount of names is larger than 10, it prompts the user to enter fewer names.

As far as I can see, the problem seems to be how you are creating the list assignedNumbers... in rare cases, 40 times trying to add a number between 1 and 10 to the list which still does not exist in the list will fail... in the example list from the error message, the number 9 is missing...

There are easier ways to shuffle a list, I think, the listUtils extension offers a method for that..