The random.choice() method of the random module in Python returns a value randomly from a list of values passed to it. So, I would expect it to return some random value every time. However, it appears that the same value is returned multiple times. For example, the following code:
import random
print(random.choice(["apple","orange","banana"]))
when executed 5 times, returns 'orange' 3 times, 'apple' 1 time and 'banana' 1 time. Why is this so? It would be helpful if anyone could provide some insight into how random.choice() works.
Aucun commentaire:
Enregistrer un commentaire