Qu

randi

Builtin index · Statistics & ML

result = randi(lo, hi, [rows], [cols], [seed=])

Input: lo, hi, rows, cols, seed · Output: result

What it is

Draws random integers. lo (number) is the smallest value that can come out; hi (number) is the largest, inclusive at both ends (MATLAB's convention, not NumPy's half-open one, so randi(1, 6) really can return 6); rows and cols (numbers, optional) give the shape of the draw, one number for a vector and two for a matrix; seed= (number, optional) makes the draw repeatable.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = randi(lo, hi, [rows], [cols], [seed=])
lo numberlo (number) is the smallest value that can come out.
hi numberhi (number) is the largest, inclusive at both ends (MATLAB's convention, not NumPy's half-open one, so randi(1, 6) really can return 6).
rows number, vector, or matrix, optionalrows and cols (numbers, optional) give the shape of the draw, one number for a vector and two for a matrix.
cols number, vector, or matrix, optionalrows and cols (numbers, optional) give the shape of the draw, one number for a vector and two for a matrix.
seed number, optionalseed= (number, optional) makes the draw repeatable.
result number, vector, or matrix
Returns a number, vector, or (rows, cols) matrix.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

u = uniform(10, 20, 5)          # 5 draws, continuous uniform on [10, 20)

g = normal(5, 2, 1000, seed=1)  # 1000 draws, mean 5, std 2 — randn is mu=0/sigma=1

d = randi(1, 6, 10)             # 10 dice rolls, inclusive both ends

k = poisson(4, 500)             # 500 draws from Poisson(lambda=4)

t = exponential(2, 500)         # 500 draws, rate=2 (mean = 1/rate = 0.5)

b = binomial(20, 0.3, 500)      # 500 draws, 20 trials at p=0.3 each

from numerics-dsp

How it works

randi(lo, hi, ...) — inclusive both ends (MATLAB's randi convention, not NumPy's half-open randint).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.