[Tutor] How to pull a random element from a list?
alan.gauld@bt.com
alan.gauld@bt.com
Wed, 25 Jul 2001 12:03:39 +0100
> I'm trying to figure out how the heck to pull an element from
> a list or dictionary at random. I have a list of words and
> need to be able to pull one at random.
One way is to pull my guessing game object framework
from Useless Python. It includes the code for selecting
a random word from a list(which is read from a file).
The essence is to generate a random integer between
0 and len(list)-1
randint() is your friend.
Alan G