[Python-checkins] r53100 - in python/branches/release25-maint: Lib/random.py Lib/test/test_random.py Misc/NEWS

raymond.hettinger python-checkins at python.org
Wed Dec 20 08:44:00 CET 2006


Author: raymond.hettinger
Date: Wed Dec 20 08:43:59 2006
New Revision: 53100
Modified:
 python/branches/release25-maint/Lib/random.py
 python/branches/release25-maint/Lib/test/test_random.py
 python/branches/release25-maint/Misc/NEWS
Log:
Bug #1590891: random.randrange don't return correct value for big number
Modified: python/branches/release25-maint/Lib/random.py
==============================================================================
--- python/branches/release25-maint/Lib/random.py	(original)
+++ python/branches/release25-maint/Lib/random.py	Wed Dec 20 08:43:59 2006
@@ -205,7 +205,7 @@
 raise ValueError, "empty range for randrange()"
 
 if n >= maxwidth:
- return istart + self._randbelow(n)
+ return istart + istep*self._randbelow(n)
 return istart + istep*int(self.random() * n)
 
 def randint(self, a, b):
Modified: python/branches/release25-maint/Lib/test/test_random.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_random.py	(original)
+++ python/branches/release25-maint/Lib/test/test_random.py	Wed Dec 20 08:43:59 2006
@@ -439,6 +439,14 @@
 self.assertEqual(k, numbits) # note the stronger assertion
 self.assert_(2**k > n > 2**(k-1)) # note the stronger assertion
 
+ def test_randrange_bug_1590891(self):
+ start = 1000000000000
+ stop = -100000000000000000000
+ step = -200
+ x = self.gen.randrange(start, stop, step)
+ self.assert_(stop < x <= start)
+ self.assertEqual((x+stop)%step, 0)
+
 _gammacoeff = (0.9999999999995183, 676.5203681218835, -1259.139216722289,
 771.3234287757674, -176.6150291498386, 12.50734324009056,
 -0.1385710331296526, 0.9934937113930748e-05, 0.1659470187408462e-06)
Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Wed Dec 20 08:43:59 2006
@@ -12,6 +12,8 @@
 Core and builtins
 -----------------
 
+- Bug #1590891: random.randrange don't return correct value for big number
+
 - Bug #1456209: In some obscure cases it was possible for a class with a
 custom ``__eq__()`` method to confuse set internals when class instances
 were used as a set's elements and the ``__eq__()`` method mutated the set.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /