A Way to Pick Unique Random Values?

I’m trying to make the game randomly
pick one from five elements inside a
Enum list. Then when the event is
fired again, it will check if that
element was already picked in previous
attempt.

If the element was picked, it would try again, a continue until it finds one it hasn’t picked yet.

Depending on how complex the final system is supposed to be, I’d lean towards the following solution as it’s not prone to indexing errors and there’s no need for any iteration or looping whatsoever:

  • create an All Enums array
  • pick one element and add it to the Final Array
  • remove the picked element from All Enums
  • rinse and repeat

That’s pretty much it, it’s like having 2 buckets and pouring contents from one into another.

I think this is what you’re after.


Some other elements that may be useful here, again depends how deep the rabbit hole goes:

  • Add Unique node: it automatically checks whether the array already contains the value and does not add it if True, and it’s kind enough to return a bool

  • Sets: the keys on the list must be unique so it’s a perfect container for what you’re doing