Skip to content

Commit 563c258

Browse files
authored
Merge pull request #13 from bashtage/random_integers-bug
BUG: Cast high to Python int to avoid overflow
2 parents 5a0a5c6 + 6a9176f commit 563c258

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

numpy/random/mtrand.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ cdef class RandomState:
11301130
"instead".format(low=low, high=high)),
11311131
DeprecationWarning)
11321132

1133-
return self.randint(low, high + 1, size=size, dtype='l')
1133+
return self.randint(low, int(high) + 1, size=size, dtype='l')
11341134

11351135
# Complicated, continuous distributions:
11361136
def standard_normal(self, size=None):

numpy/random/tests/test_randomstate.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,14 @@ def test_random_integers_max_int(self):
436436

437437
desired = np.iinfo('l').max
438438
assert_equal(actual, desired)
439+
with suppress_warnings() as sup:
440+
w = sup.record(DeprecationWarning)
441+
typer = np.dtype('l').type
442+
actual = random.random_integers(typer(np.iinfo('l').max),
443+
typer(np.iinfo('l').max))
444+
assert_(len(w) == 1)
445+
assert_equal(actual, desired)
446+
439447

440448
def test_random_integers_deprecated(self):
441449
with warnings.catch_warnings():

0 commit comments

Comments
 (0)