[pypy-svn] r77749 - in pypy/branch/fast-forward/pypy/module/_random: . test
afa at codespeak.net
afa at codespeak.net
Sun Oct 10 00:27:55 CEST 2010
Author: afa
Date: Sun Oct 10 00:27:53 2010
New Revision: 77749
Modified:
pypy/branch/fast-forward/pypy/module/_random/interp_random.py
pypy/branch/fast-forward/pypy/module/_random/test/test_random.py
Log:
random.jumpahead() now accepts long integers
Modified: pypy/branch/fast-forward/pypy/module/_random/interp_random.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_random/interp_random.py (original)
+++ pypy/branch/fast-forward/pypy/module/_random/interp_random.py Sun Oct 10 00:27:53 2010
@@ -81,9 +81,14 @@
self._rnd.index = space.int_w(w_item)
setstate.unwrap_spec = ['self', ObjSpace, W_Root]
- def jumpahead(self, n):
+ def jumpahead(self, space, w_n):
+ if space.is_true(space.isinstance(w_n, space.w_long)):
+ num = space.bigint_w(w_n)
+ n = intmask(num.uintmask())
+ else:
+ n = space.int_w(w_n)
self._rnd.jumpahead(n)
- jumpahead.unwrap_spec = ['self', int]
+ jumpahead.unwrap_spec = ['self', ObjSpace, W_Root]
def getrandbits(self, space, k):
if k <= 0:
Modified: pypy/branch/fast-forward/pypy/module/_random/test/test_random.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_random/test/test_random.py (original)
+++ pypy/branch/fast-forward/pypy/module/_random/test/test_random.py Sun Oct 10 00:27:53 2010
@@ -82,8 +82,14 @@
state2 = rnd.getstate() # seed() to improve the resolution)
assert state1 != state2
+ def test_jumpahead(self):
+ import sys
+ import _random
+ rnd = _random.Random()
+ rnd.jumpahead(100)
+ rnd.jumpahead(sys.maxint + 2)
+
def test_randbits(self):
- import math
import _random
rnd = _random.Random()
for n in range(1, 10) + range(10, 1000, 15):
More information about the Pypy-commit
mailing list