I have a list [1,2,3,3]
, and I want to select a random element from this list multiple times. However, I don't want my random generator to select the same element from the same index more than once.
What I'm currently have:
[1,2,3,3] --> [2] with index 1
[1,2,3,3] --> [1] with index 0
[1,2,3,3] --> [2] with index 1 (this is wrong because chose the same index)
What I want is:
[1,2,3,3] --> [2] with index 1
[1,2,3,3] --> [1] with index 0
[1,2,3,3] --> [3] with index 3
[1,2,3,3] --> [3] with index 4 (this is perfect, no repeats!)
What should I do to solve this issue? The function random.choice(...)
itself doesn't solve this.
UPDATE: I noticed some of you recommended me to use shuffle. It was a really good idea. But, what if I want to keep track of the original index too at later time? I don't think shuffle and pop could do that, right?