Communications Toolbox |

Generate matrix of uniformly distributed random integers

**Syntax**

out = randint out = randint(m); out = randint(m,n); out = randint(m,n,range); out = randint(m,n,range,state);

**Description**

```
out = randint
```

generates a random scalar that is either zero or one, with equal probability.

```
out = randint(m)
```

generates an `m`

-by-`m`

binary matrix, each of whose entries independently takes the value zero with probability 1/2.

```
out = randint(m,n)
```

generates an `m`

-by-`n`

binary matrix, each of whose entries independently takes the value zero with probability 1/2.

```
out = randint(m,n,range)
```

generates an `m`

-by-`n`

integer matrix. If `range`

is zero, then `out`

is a zero matrix. Otherwise, the entries are uniformly distributed and independently chosen from the range:

- [0,
`range`

-1] if`range`

is a positive integer - [
`range`

+1, 0] if`range`

is a negative integer - Between
`min`

and`max`

, inclusive, if`range = [min,max]`

or`[max,min]`

```
out = randint(m,n,range,state)
```

is the same as the syntax above, except that it first resets the state of MATLAB's uniform random number generator `rand`

to the integer `state`

.

**Examples**

To generate a 10-by-10 matrix whose elements are uniformly distributed in the range from 0 to 7, you can use either of the following commands.

out = randint(10,10,[0,7]); out = randint(10,10,8);

**See Also**

`rand`

, `randsrc`

, ```
randerr
```

randerr | randsrc |