python - Not using an element in a list once randomly chosen -
i have programme randomly chooses characters, this:
things = ("doge", "cat", "actual dog", "rabbit") in range(20): print random.randint(1, len(things))-1 i want doge not selected again. 1 time randomly selected list things. how can this? please give method can work in variety of situations. thanks!
you can utilize random.sample. example:
import random x = range(10) y = random.sample(x, 4) # pick 4 distinct elements x python python-2.7
No comments:
Post a Comment