# randi (RandStream)

Uniformly distributed pseudorandom integers

## Syntax

```r = randi(s,imax,n) r = randi(s,imax,m,n) r = randi(s,imax,[m,n]) r = randi(s,imax,m,n,p,...) r = randi(s,imax,[m,n,p,...]) r = randi(s,imax) r = randi(s,imax,size(A)) r = randi(s,[imin,imax],...) r = randi(...,classname) ```

## Description

`r = randi(s,imax,n)` returns an `n`-by-`n` matrix containing pseudorandom integer values drawn from the discrete uniform distribution on `1:imax`. `randi` draws those values from the random stream `s`.

`r = randi(s,imax,m,n)` or ```r = randi(s,imax,[m,n])``` returns an `m`-by-`n` matrix.

`r = randi(s,imax,m,n,p,...)` or ```r = randi(s,imax,[m,n,p,...])``` returns an `m`-by-`n`-by-`p`-by-... array.

`r = randi(s,imax)` returns a scalar.

`r = randi(s,imax,size(A))` returns an array the same size as `A`.

`r = randi(s,[imin,imax],...)` returns an array containing integer values drawn from the discrete uniform distribution on `imin:imax`.

`r = randi(...,classname)` returns an array of integer values of class `classname`. `classname` does not support 64-bit integers.

### Note

The size inputs `m`, `n`, `p`, ... should be nonnegative integers. Negative integers are treated as 0.

The arrays returned by `randi` might contain repeated integer values. This is sometimes referred to as sampling with replacement. To get unique integer values, sometimes referred to as sampling without replacement, use ```randperm (RandStream)```.

The sequence of numbers produced by `randi` is determined by the internal state of the random stream `s`. `randi` uses one uniform value from `s` to generate each integer value. Resetting `s` to the same fixed state allows computations to be repeated. Setting the stream to different states leads to unique computations, however, it does not improve any statistical properties.