summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-09-07 20:04:42 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-09-07 20:04:42 (GMT)
commitf015b3f5f6ccaa848bdb96306d2f4120bdbc46c7 (patch)
tree8f89e0ac3904073615955343edd564f35de68c19
parent05a505f106f8a77f3ea753caa3c05ea59af3b297 (diff)
downloadcpython-f015b3f5f6ccaa848bdb96306d2f4120bdbc46c7.zip
cpython-f015b3f5f6ccaa848bdb96306d2f4120bdbc46c7.tar.gz
cpython-f015b3f5f6ccaa848bdb96306d2f4120bdbc46c7.tar.bz2
Neaten-up comments and warning message.
-rw-r--r--Lib/random.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/random.py b/Lib/random.py
index b2a3d51..0aee06e 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -221,9 +221,8 @@ class Random(_random.Random):
getrandbits = self.getrandbits
# Only call self.getrandbits if the original random() builtin method
# has not been overridden or if a new getrandbits() was supplied.
- # This assures that the two methods correspond.
if type(self.random) is BuiltinMethod or type(getrandbits) is Method:
- r = getrandbits(k) # 0 <= r < 2**k
+ r = getrandbits(k) # 0 <= r < 2**k
while r >= n:
r = getrandbits(k)
return r
@@ -231,11 +230,12 @@ class Random(_random.Random):
# so we can only use random() from here.
if k > bpf:
_warn("Underlying random() generator does not supply \n"
- "enough bits to choose from a population range this large")
+ "enough bits to choose from a population range this large.\n"
+ "To remove the range limitation, add a getrandbits() method.")
return int(self.random() * n)
random = self.random
N = 1 << k
- r = int(N * random())
+ r = int(N * random()) # 0 <= r < 2**k
while r >= n:
r = int(N * random())
return r