[Tutor] When I print random.random

Steven D'Aprano steve at pearwood.info
Sat Jan 15 06:19:24 CET 2011


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?

Because random.random() is defined to always return a float between 0 
and 1. That's what it does.

If you want a random whole number, you can call random.randint or 
random.randrange. See the Fine Manual for the difference between them, 
or at the interactive interpreter, call:

help(random.randint)
help(random.randrange)

and read what they say. Then if you still have any questions, ask.



-- 
Steven



More information about the Tutor mailing list