randi

Generates random integers.

Syntax

v = randi(imax)

v = randi(imax, n, ...)

v = randi(imax, n, m, ...)

v = randi([imin,imax], ...

Inputs

imin
The minimum integer to produce (default: 1).
Type: integer
Dimension: scalar
imax
The maximum integer to produce, up to 2^31-1.
Type: integer
Dimension: scalar
m, n, ...
The length of each dimension in the output matrix.
When only n is specified the matrix is n x n.
Type: integer
Dimension: scalar

Outputs

v
The random integers.

Examples

Generate a 3x8 matrix of random integers on the interval [2,8].

rand('seed', 2023);
v = randi([2,8], 3, 8)
v = [Matrix] 3 x 8
4  5  2  7  2  5  5  2
6  6  2  5  3  5  6  5
8  6  2  4  7  6  5  4