Skip to content

Commit 12bd0bd

Browse files
committed
Issue 6261: Clarify behavior of random.uniform().
1 parent ff08784 commit 12bd0bd

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

Doc/library/random.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ be found in any statistics text.
142142
Return a random floating point number *N* such that ``a <= N <= b`` for
143143
``a <= b`` and ``b <= N <= a`` for ``b < a``.
144144

145+
The end-point value ``b`` may or may not be included in the range
146+
depending on floating-point rounding in the equation ``a + (b-a) * random()``.
145147

146148
.. function:: triangular(low, high, mode)
147149

Lib/random.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def sample(self, population, k):
333333
## -------------------- uniform distribution -------------------
334334

335335
def uniform(self, a, b):
336-
"""Get a random number in the range [a, b)."""
336+
"Get a random number in the range [a, b) or [a, b] depending on rounding."
337337
return a + (b-a) * self.random()
338338

339339
## -------------------- triangular --------------------

0 commit comments

Comments
 (0)