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
2010-02-01 21:48:09
random() -> x in the interval [0, 1)That is, including 0.
telliott99
2010-02-01 21:49:32
@telliott99: That's (almost) exactly what I said.
SLaks
2010-02-01 21:49:56
+1 for being the only answer not to rely on sci-fi math notation!
Jørn Schou-Rode
2010-02-01 22:13:09
@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
2010-02-02 02:37:51
@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
2010-02-02 08:52:18
+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
2010-02-01 21:49:26
For an explanation of the bracket/parent range notation, look here: http://en.wikipedia.org/wiki/Interval_(mathematics)#Terminology
Ben Gartner
2010-02-01 21:52:10
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
2010-02-01 21:54:12
It's much better to link to the real documentation when you're writing on a webpage.
Glenn Maynard
2010-02-01 22:36:25
+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
2010-02-01 21:50:41
I like your answer best. Python has a fantastic internal help system and people should be encouraged to use it.
Omnifarious
2010-02-01 21:52:39