[Python-checkins]
python/dist/src/Lib/test test_random.py, 1.12.8.2, 1.12.8.3
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Sun Oct 5 19:35:40 EDT 2003
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv17515/Lib/test
Modified Files:
Tag: release23-maint
test_random.py
Log Message:
SF bug #812202: randint is always even
* Extend rangrange() to return meaningful results when the range is
larger than 2**53. Only applies to the MersenneTwister. WichmannHill
was left alone in the absence of a proof showing how multiple calls
could be combined to produce long bit streams.
* WichmannHill was missing from __all__.
Index: test_random.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_random.py,v
retrieving revision 1.12.8.2
retrieving revision 1.12.8.3
diff -C2 -d -r1.12.8.2 -r1.12.8.3
*** test_random.py 5 Sep 2003 21:40:30 -0000 1.12.8.2
--- test_random.py 5 Oct 2003 23:35:38 -0000 1.12.8.3
***************
*** 221,224 ****
--- 221,256 ----
self.gen.seed(seed)
+ def test_53_bits_per_float(self):
+ # This should pass whenever a C double has 53 bit precision.
+ span = 2 ** 53
+ cum = 0
+ for i in xrange(100):
+ cum |= int(self.gen.random() * span)
+ self.assertEqual(cum, span-1)
+
+ def test_bigrand(self):
+ # The randrange routine should build-up the required number of bits
+ # in stages so that all bit positions are active.
+ span = 2 ** 500
+ cum = 0
+ for i in xrange(100):
+ r = self.gen.randrange(span)
+ self.assert_(0 <= r < span)
+ cum |= r
+ self.assertEqual(cum, span-1)
+
+ def test_bigrand_ranges(self):
+ for i in [40,80, 160, 200, 211, 250, 375, 512, 550]:
+ start = self.gen.randrange(2 ** i)
+ stop = self.gen.randrange(2 ** (i-2))
+ if stop <= start:
+ return
+ self.assert_(start <= self.gen.randrange(start, stop) < stop)
+
+ def test_rangelimits(self):
+ for start, stop in [(-2,0), (-(2**60)-2,-(2**60)), (2**60,2**60+2)]:
+ self.assertEqual(Set(range(start,stop)),
+ Set([self.gen.randrange(start,stop) for i in xrange(100)]))
+
_gammacoeff = (0.9999999999995183, 676.5203681218835, -1259.139216722289,
771.3234287757674, -176.6150291498386, 12.50734324009056,
More information about the Python-checkins
mailing list