@@ -949,33 +949,42 @@ cdef class RandomState:
949949 key = np .dtype (dtype ).name
950950 if not key in _randint_type :
951951 raise TypeError ('Unsupported dtype "%s" for randint' % key )
952+
952953 lowbnd , highbnd = _randint_type [key ]
953954
954- if low < lowbnd :
955+ # TODO: Do not cast these inputs to Python int
956+ #
957+ # This is a workaround until gh-8851 is resolved (bug in NumPy
958+ # integer comparison and subtraction involving uint64 and non-
959+ # uint64). Afterwards, remove these two lines.
960+ ilow = int (low )
961+ ihigh = int (high )
962+
963+ if ilow < lowbnd :
955964 raise ValueError ("low is out of bounds for %s" % (key ,))
956- if high > highbnd :
965+ if ihigh > highbnd :
957966 raise ValueError ("high is out of bounds for %s" % (key ,))
958- if low >= high :
967+ if ilow >= ihigh :
959968 raise ValueError ("low >= high" )
960969
961970 if key == 'int32' :
962- ret = _rand_int32 (low , high - 1 , size , & self .rng_state , self .lock )
971+ ret = _rand_int32 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
963972 elif key == 'int64' :
964- ret = _rand_int64 (low , high - 1 , size , & self .rng_state , self .lock )
973+ ret = _rand_int64 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
965974 elif key == 'int16' :
966- ret = _rand_int16 (low , high - 1 , size , & self .rng_state , self .lock )
975+ ret = _rand_int16 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
967976 elif key == 'int8' :
968- ret = _rand_int8 (low , high - 1 , size , & self .rng_state , self .lock )
977+ ret = _rand_int8 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
969978 elif key == 'uint64' :
970- ret = _rand_uint64 (low , high - 1 , size , & self .rng_state , self .lock )
979+ ret = _rand_uint64 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
971980 elif key == 'uint32' :
972- ret = _rand_uint32 (low , high - 1 , size , & self .rng_state , self .lock )
981+ ret = _rand_uint32 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
973982 elif key == 'uint16' :
974- ret = _rand_uint16 (low , high - 1 , size , & self .rng_state , self .lock )
983+ ret = _rand_uint16 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
975984 elif key == 'uint8' :
976- ret = _rand_uint8 (low , high - 1 , size , & self .rng_state , self .lock )
985+ ret = _rand_uint8 (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
977986 elif key == 'bool' :
978- ret = _rand_bool (low , high - 1 , size , & self .rng_state , self .lock )
987+ ret = _rand_bool (ilow , ihigh - 1 , size , & self .rng_state , self .lock )
979988
980989 if size is None :
981990 if dtype in (np .bool , np .int , np .long ):
@@ -1021,7 +1030,7 @@ cdef class RandomState:
10211030 ----------
10221031 a : 1-D array-like or int
10231032 If an ndarray, a random sample is generated from its elements.
1024- If an int, the random sample is generated as if a was np.arange(n )
1033+ If an int, the random sample is generated as if a were np.arange(a )
10251034 size : int or tuple of ints, optional
10261035 Output shape. If the given shape is, e.g., ``(m, n, k)``, then
10271036 ``m * n * k`` samples are drawn. Default is None, in which case a
@@ -1035,7 +1044,7 @@ cdef class RandomState:
10351044
10361045 Returns
10371046 -------
1038- samples : 1-D ndarray, shape (size,)
1047+ samples : single item or ndarray
10391048 The generated random samples
10401049
10411050 Raises
@@ -4094,8 +4103,8 @@ cdef class RandomState:
40944103 Instead of specifying the full covariance matrix, popular
40954104 approximations include:
40964105
4097- - Spherical covariance (* cov* is a multiple of the identity matrix)
4098- - Diagonal covariance (* cov* has non-negative elements, and only on
4106+ - Spherical covariance (` cov` is a multiple of the identity matrix)
4107+ - Diagonal covariance (` cov` has non-negative elements, and only on
40994108 the diagonal)
41004109
41014110 This geometrical property can be seen in two dimensions by plotting
@@ -4507,6 +4516,7 @@ cdef class RandomState:
45074516 with self .lock :
45084517 for i in reversed (range (1 , n )):
45094518 j = random_interval (& self .rng_state , i )
4519+ if i == j : continue # i == j is not needed and memcpy is undefined.
45104520 buf [...] = x [j ]
45114521 x [j ] = x [i ]
45124522 x [i ] = buf
0 commit comments