How do make a function that creates a sequence of n random numbers?

Asun Friere afriere at yahoo.co.uk
Tue Feb 17 19:42:29 EST 2004


shivermetimbers15 at yahoo.com (shivermetimbers15) wrote in message news:<8e3e8c6c.0402171124.1183350c at posting.google.com>...
> I'm new to Python, as you can tell, and I'm interested in how to do this.


As well as using random.random() consider whether some of the other
methods in the random module might serve your needs, eg.

>>> import random
>>> random.randrange(500,1000)
806
>>> [random.randrange(0, 10) for n in range(8)]
[4, 1, 6, 5, 5, 3, 0, 5]
>>> a = ['one', 'two', 'three', 'four', 'five']
>>>random.choice(a)
'three'
>>> random.shuffle(a)
>>> a
['four', 'two', 'one', 'three', 'five']



More information about the Python-list mailing list