tags:

views:

229

answers:

3

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

+8  A: 

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

However, it can return 0.

SLaks
random() -> x in the interval [0, 1)That is, including 0.
telliott99
@telliott99: That's (almost) exactly what I said.
SLaks
+1 for being the only answer not to rely on sci-fi math notation!
Jørn Schou-Rode
@Jørn Schou-Rode, I learned about open and closed intervals sometime in elementary to high-school. I can't remember when. People, especially programmers, should learn to understand them if they don't already.
Omnifarious
@Omnifarious: it was so long time ago that i forgot about them and i actually thought that that was a typo in their docs
daniels
+10  A: 

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

fatcat1111
For an explanation of the bracket/parent range notation, look here: http://en.wikipedia.org/wiki/Interval_(mathematics)#Terminology
Ben Gartner
I think Python's internal help system (as mentioned in another answer) is much more immediately accessible when you're programming in Python. `help(random.random)` would've given the OP the information (s)he needed.
Omnifarious
It's much better to link to the real documentation when you're writing on a webpage.
Glenn Maynard
+14  A: 
>>> help(random.random)
Help on built-in function random:

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

That means 1 is excluded.

Thomas Ahle
I like your answer best. Python has a fantastic internal help system and people should be encouraged to use it.
Omnifarious