How to print random strings

Magnus Lycka lycka at carmen.se
Thu Nov 3 09:26:17 EST 2005


theboringdays at gmail.com wrote:
> So how would I go about have 5 strings, and running a program that will
> randomly pick one of those to print?

 >>> import random
 >>> text = "Perhaps reading the manual is a good idea?".split()
 >>> random.choice(text)
'is'
 >>> random.choice(text)
'reading'
 >>> random.choice(text)
'a'
 >>> random.choice(text)
'the'
 >>> random.choice(text)
'Perhaps'

See http://docs.python.org/lib/module-random.html



More information about the Python-list mailing list