From 7f1a1658bfc05cbf5ccf14ddbb123576c5fb0ad2 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 11 Jun 2009 23:14:12 +0000 Subject: [PATCH] Issue 6261: Clarify behavior of random.uniform(). --- Doc/library/random.rst | 2 ++ Lib/random.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Doc/library/random.rst b/Doc/library/random.rst index ecfa607e189a..6c7a04dca440 100644 --- a/Doc/library/random.rst +++ b/Doc/library/random.rst @@ -142,6 +142,8 @@ be found in any statistics text. Return a random floating point number *N* such that ``a <= N <= b`` for ``a <= b`` and ``b <= N <= a`` for ``b < a``. + The end-point value ``b`` may or may not be included in the range + depending on floating-point rounding in the equation ``a + (b-a) * random()``. .. function:: triangular(low, high, mode) diff --git a/Lib/random.py b/Lib/random.py index 9279d1d699a9..3c1fab213ab3 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -333,7 +333,7 @@ class Random(_random.Random): ## -------------------- uniform distribution ------------------- def uniform(self, a, b): - """Get a random number in the range [a, b).""" + "Get a random number in the range [a, b) or [a, b] depending on rounding." return a + (b-a) * self.random() ## -------------------- triangular -------------------- -- 2.47.3