Range of python's random.random() from the standard library

Viewed 26084

Does python's random.random() ever return 1.0 or does it only return up until 0.9999..?

5 Answers
>>> help(random.random)
Help on built-in function random:

random(...)
    random() -> x in the interval [0, 1).

That means 1 is excluded.

Docs are here: http://docs.python.org/library/random.html

...random(), which generates a random float uniformly in the semi-open range [0.0, 1.0).

So, the return value will be greater than or equal to 0, and less than 1.0.

Python's random.random function returns numbers that are less than, but not equal to, 1.

However, it can return 0.

Related