bundles / numpy 2.4.4 / numpy / random / RandomState / randint
cython_function_or_method
numpy.random:RandomState.randint
Signature
def randint ( low , high = None , size = None , dtype = <class 'int'> ) Summary
Return random integers from low (inclusive) to high (exclusive).
Extended Summary
Return random integers from the "discrete uniform" distribution of the specified dtype in the "half-open" interval [low, high). If high is None (the default), then results are from [0, low).
Parameters
low: int or array-like of intsLowest (signed) integers to be drawn from the distribution (unless
high=None, in which case this parameter is one above the highest such integer).high: int or array-like of ints, optionalIf provided, one above the largest (signed) integer to be drawn from the distribution (see above for behavior if
high=None). If array-like, must contain integer valuessize: int or tuple of ints, optionalOutput shape. If the given shape is, e.g.,
(m, n, k), thenm * n * ksamples are drawn. Default is None, in which case a single value is returned.dtype: dtype, optionalDesired dtype of the result. Byteorder must be native. The default value is long.
Returns
out: int or ndarray of intssize-shaped array of random integers from the appropriate distribution, or a single such random int ifsizenot provided.
Examples
np.random.randint(2, size=10)
✗np.random.randint(1, size=10)
✓np.random.randint(5, size=(2, 4))
✗np.random.randint(1, [3, 5, 10])
✗np.random.randint([1, 5, 7], 10)
✗np.random.randint([1, 3, 5, 7], [[10], [20]], dtype=np.uint8)
✗See also
- random.Generator.integers
which should be used for new code.
- random_integers
similar to
randint, only for the closed interval [low,high], and 1 is the lowest value ifhighis omitted.
Aliases
-
numpy.random.randint -
numpy.random.RandomState.randint