[pypy-svn] r32427 - in pypy/dist/pypy/module/_random: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Sun Sep 17 21:13:47 CEST 2006
Author: cfbolz
Date: Sun Sep 17 21:13:45 2006
New Revision: 32427
Modified:
pypy/dist/pypy/module/_random/interp_random.py
pypy/dist/pypy/module/_random/test/test_random.py
Log:
everything not tested is broken. So was the getrandbits method.
Modified: pypy/dist/pypy/module/_random/interp_random.py
==============================================================================
--- pypy/dist/pypy/module/_random/interp_random.py (original)
+++ pypy/dist/pypy/module/_random/interp_random.py Sun Sep 17 21:13:45 2006
@@ -87,7 +87,7 @@
k -= 32
r = self._rnd.genrand32()
if k < 0:
- r >>= (32 - k)
+ k >>= (32 - k)
bytesarray[i + 0] = r & r_uint(0xff)
bytesarray[i + 1] = (r >> 8) & r_uint(0xff)
bytesarray[i + 2] = (r >> 16) & r_uint(0xff)
@@ -98,7 +98,7 @@
w_eight = space.newlong(8)
for byte in bytesarray:
w_result = space.lshift(
- space.and_(w_result, space.newlong(int(byte))), w_eight)
+ space.or_(w_result, space.newlong(int(byte))), w_eight)
return w_result
getrandbits.unwrap_spec = ['self', ObjSpace, int]
Modified: pypy/dist/pypy/module/_random/test/test_random.py
==============================================================================
--- pypy/dist/pypy/module/_random/test/test_random.py (original)
+++ pypy/dist/pypy/module/_random/test/test_random.py Sun Sep 17 21:13:45 2006
@@ -39,11 +39,19 @@
import _random
rnd = _random.Random()
rnd.seed()
- obj = "spam and eggs"
- nums = []
- for o in [obj, hash(obj), -hash(obj)]:
- rnd.seed(o)
- nums.append([rnd.random() for i in range(100)])
- n1 = nums[0]
- for n2 in nums[1:]:
- assert n1 == n2
+ for obj in ["spam and eggs", 3.14, 1+2j, 'a', tuple('abc')]:
+ nums = []
+ for o in [obj, hash(obj), -hash(obj)]:
+ rnd.seed(o)
+ nums.append([rnd.random() for i in range(100)])
+ n1 = nums[0]
+ for n2 in nums[1:]:
+ assert n1 == n2
+
+ def test_randbits(self):
+ import math
+ import _random
+ rnd = _random.Random()
+ for n in range(10, 200, 10):
+ n = rnd.getrandbits(n)
+ assert int(math.log(n) / math.log(2)) <= n
More information about the Pypy-commit
mailing list