[Tutor] When I print random.random

Wayne Werner waynejwerner at gmail.com
Sat Jan 15 06:15:27 CET 2011


On Fri, Jan 14, 2011 at 9:25 PM, bob gailer <bgailer at gmail.com> wrote:

>  On 1/14/2011 10:02 PM, walter weston wrote:
>
> when I print random.random() it always returns a float why is this? how do
> I change it to a whole number?
>
>
> That depends on what behavior you want.
>
> If you RTFM you will see:
>  random.random() Return the next random floating point number in the range
> [0.0, 1.0). The Python tool for converting float to integer is the int
> function.
>
> However int(random.random() ) will always return 0.
>
> In what range do you want the integers to fall?
>

The documentation in general is a fine source for learning new
functionality: http://docs.python.org/library/random.html

<http://docs.python.org/library/random.html>HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110114/defa0bed/attachment-0001.html>


More information about the Tutor mailing list