random number including 1 - i.e. [0,1]
John Yeung
gallium.arsenide at gmail.com
Tue Jun 9 21:32:57 EDT 2009
On Jun 9, 8:39 pm, Paul McGuire <pt... at austin.rr.com> wrote:
> Are you trying to generate a number in the
> range [0,n] by multiplying a random function that
> returns [0,1] * n? If so, then you want to do
> this using: int(random.random()*(n+1)) This will
> give equal chance of getting any number from 0 to n.
Better still is simply
random.randint(0, n)
For other discrete random choices, you may find randrange() or choice
() useful.
John
More information about the Python-list
mailing list