cpython: 1f51867fe50e (original) (raw)
Mercurial > cpython
changeset 85985:1f51867fe50e
Issue #19169: Micro refactoring with a micro benefit for brevity and speed. [#19169]
Raymond Hettinger python@rcn.com | |
---|---|
date | Sat, 05 Oct 2013 17🔞36 -0700 |
parents | 43e94e77329e |
children | 94246efe2275 |
files | Lib/random.py |
diffstat | 1 files changed, 2 insertions(+), 2 deletions(-)[+] [-] Lib/random.py 4 |
line wrap: on
line diff
--- a/Lib/random.py +++ b/Lib/random.py @@ -220,10 +220,11 @@ class Random(_random.Random): Method=_MethodType, BuiltinMethod=_BuiltinMethodType): "Return a random int in the range [0,n). Raises ValueError if n==0."
random = self.random[](#l1.7) getrandbits = self.getrandbits[](#l1.8) # Only call self.getrandbits if the original random() builtin method[](#l1.9) # has not been overridden or if a new getrandbits() was supplied.[](#l1.10)
if type(self.random) is BuiltinMethod or type(getrandbits) is Method:[](#l1.11)
if type(random) is BuiltinMethod or type(getrandbits) is Method:[](#l1.12) k = n.bit_length() # don't use (n-1) here because n can be 1[](#l1.13) r = getrandbits(k) # 0 <= r < 2**k[](#l1.14) while r >= n:[](#l1.15)
@@ -231,7 +232,6 @@ class Random(_random.Random): return r # There's an overriden random() method but no new getrandbits() method, # so we can only use random() from here.
random = self.random[](#l1.20) if n >= maxsize:[](#l1.21) _warn("Underlying random() generator does not supply \n"[](#l1.22) "enough bits to choose from a population range this large.\n"[](#l1.23)