random number including 1 - i.e. [0,1]

Esmail ebonak at hotmail.com
Tue Jun 9 23:33:39 CEST 2009


Hi,

random.random() will generate a random value in the range [0, 1).

Is there an easy way to generate random values in the range [0, 1]?
I.e., including 1?

I am implementing an algorithm and want to stay as true to the
original design specifications as possible though I suppose the
difference between the two max values might be minimal.

Thanks,
Esmail

ps: I'm confused by the docs for uniform():

random.uniform(a, b)
     Return a random floating point number N such that a <= N <= b for a <= b

this seems to imply an inclusive range, ie. [a,b]

but this seems to contradict it:

In [3]: random.uniform?
Type:		instancemethod
Base Class:	<type 'instancemethod'>
String Form:	<bound method Random.uniform of <random.Random object at 0x8c50754>>
Namespace:	Interactive
File:		/usr/lib/python2.6/random.py
Definition:	random.uniform(self, a, b)
Docstring:
     Get a random number in the range [a, b).




More information about the Python-list mailing list