summaryrefslogtreecommitdiffstats
path: root/Lib/random.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2013-10-06 00:18:36 (GMT)
committerRaymond Hettinger <python@rcn.com>2013-10-06 00:18:36 (GMT)
commitf77cdbeff71b24debf32c9c6605148ae002be5e2 (patch)
tree09dd1c282f3ebf532c4b6df506773f0cd89e7ca7 /Lib/random.py
parentfacd0a346f34c97dcbea315b7652503196c753f5 (diff)
downloadcpython-f77cdbeff71b24debf32c9c6605148ae002be5e2.zip
cpython-f77cdbeff71b24debf32c9c6605148ae002be5e2.tar.gz
cpython-f77cdbeff71b24debf32c9c6605148ae002be5e2.tar.bz2
Issue #19169: Micro refactoring with a micro benefit for brevity and speed.
Diffstat (limited to 'Lib/random.py')
-rw-r--r--Lib/random.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 4ebc757..3fac699 100644
--- 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
getrandbits = self.getrandbits
# Only call self.getrandbits if the original random() builtin method
# has not been overridden or if a new getrandbits() was supplied.
- if type(self.random) is BuiltinMethod or type(getrandbits) is Method:
+ if type(random) is BuiltinMethod or type(getrandbits) is Method:
k = n.bit_length() # don't use (n-1) here because n can be 1
r = getrandbits(k) # 0 <= r < 2**k
while r >= n:
@@ -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
if n >= maxsize:
_warn("Underlying random() generator does not supply \n"
"enough bits to choose from a population range this large.\n"