Esmail writes:

> 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.

You could generate from a larger range and reject the values that
you do not want: generate from [0, 2), say, until you get a value
in [0, 1].

If you generate from [0, 1 + epsilon) with small epsilon,
rejections will be rare.

(I didn't notice this suggestion in the thread, so I'm voicing it
just in case it's not there yet.)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to