[pypy-commit] pypy stdlib-2.7.6: reapply pypy random.py modifications
bdkearns
noreply at buildbot.pypy.org
Sun Mar 2 01:19:17 CET 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch: stdlib-2.7.6
Changeset: r69588:cc9aacc860c0
Date: 2014-03-01 19:06 -0500
http://bitbucket.org/pypy/pypy/changeset/cc9aacc860c0/
Log: reapply pypy random.py modifications
diff --git a/lib-python/2.7/random.py b/lib-python/2.7/random.py
--- a/lib-python/2.7/random.py
+++ b/lib-python/2.7/random.py
@@ -41,7 +41,6 @@
from __future__ import division
from warnings import warn as _warn
-from types import MethodType as _MethodType, BuiltinMethodType as _BuiltinMethodType
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
from os import urandom as _urandom
@@ -239,8 +238,7 @@
return self.randrange(a, b+1)
- def _randbelow(self, n, _log=_log, _int=int, _maxwidth=1L<<BPF,
- _Method=_MethodType, _BuiltinMethod=_BuiltinMethodType):
+ def _randbelow(self, n, _log=_log, _int=int, _maxwidth=1L<<BPF):
"""Return a random int in the range [0,n)
Handles the case where n has more bits than returned
@@ -255,7 +253,8 @@
# 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:
+ if (self.random == super(Random, self).random or
+ getrandbits != super(Random, self).getrandbits):
k = _int(1.00001 + _log(n-1, 2.0)) # 2**k > n-1 > 2**(k-2)
r = getrandbits(k)
while r >= n:
More information about the pypy-commit
mailing list