[Python-checkins] r84596 - python/branches/py3k/Lib/random.py
raymond.hettinger
python-checkins at python.org
Tue Sep 7 22:04:42 CEST 2010
Author: raymond.hettinger
Date: Tue Sep 7 22:04:42 2010
New Revision: 84596
Log:
Neaten-up comments and warning message.
Modified:
python/branches/py3k/Lib/random.py
Modified: python/branches/py3k/Lib/random.py
==============================================================================
--- python/branches/py3k/Lib/random.py (original)
+++ python/branches/py3k/Lib/random.py Tue Sep 7 22:04:42 2010
@@ -221,9 +221,8 @@
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 @@
# 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
More information about the Python-checkins
mailing list