On Jun 10, 12:01 am, alex23 <wuwe...@gmail.com> wrote: > On Jun 10, 11:32 am, John Yeung <gallium.arsen...@gmail.com> wrote: > > > On Jun 9, 8:39 pm, Paul McGuire <pt...@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) > > There's a big difference between randint - which generates _integers_ > in the range 0 & n - and the OPs request for generating random > floating point values between & inclusive of 0 & n.
Alex, did you bother to read what I quoted? Paul McGuire suggested an alternative in case the OP was choosing integers in a roundabout way. I was merely pointing out that Paul's solution can be more simply achieved using a library function. John -- http://mail.python.org/mailman/listinfo/python-list