Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Uniformly distributed pseudorandom integers

`X = randi(imax)`

`X = randi(imax,n)`

`X = randi(imax,sz1,...,szN)`

`X = randi(imax,sz)`

`X = randi(imax,classname)`

`X = randi(imax,n,classname)`

`X = randi(imax,sz1,...,szN,classname)`

`X = randi(imax,sz,classname)`

`X = randi(imax,'like',p)`

`X = randi(imax,n,'like',p)`

`X = randi(imax,sz1,...,szN,'like',p)`

`X = randi(imax,sz,'like',p)`

`X = randi([imin,imax],___)`

`X = randi(`

returns
a pseudorandom scalar integer between `imax`

)`1`

and `imax`

.

`X = randi(`

returns
an `imax`

,`sz1,...,szN`

)`sz1`

-by-...-by-`szN`

array where `sz1,...,szN`

indicates
the size of each dimension. For example, `randi(10,3,4)`

returns
a 3-by-4 array of pseudorandom integers between 1 and 10.

`X = randi(`

returns
an `imax`

,`sz1,...,szN`

,`classname`

)`sz1`

-by-...-by-`szN`

array of
data type `classname`

.

`X = randi(`

returns
an `imax`

,`sz1,...,szN`

,'like',`p`

)`sz1`

-by-...-by-`szN`

array like `p`

.

The sequence of numbers produced by

`randi`

is determined by the internal settings of the uniform pseudorandom number generator that underlies`rand`

,`randi`

, and`randn`

. You can control that shared random number generator using`rng`

.The arrays returned by

`randi`

might contain repeated integer values. This behavior is sometimes referred to as sampling with replacement. Use`randperm`

if you require all unique values.

`RandStream`

| `rand`

| `randn`

| `randperm`

| `rng`