diff -r e9554199620f Lib/random.py --- a/Lib/random.py Fri Oct 04 20:35:34 2013 -0600 +++ b/Lib/random.py Sat Oct 05 12:28:36 2013 +0100 @@ -220,18 +220,22 @@ Method=_MethodType, BuiltinMethod=_BuiltinMethodType): "Return a random int in the range [0,n). Raises ValueError if n==0." + # Shorten some names for brevity + 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: r = getrandbits(k) 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"