randi
Uniformly distributed random integers
Syntax
Description
X = randi(imax,sz1,...,szN)sz1-by-...-by-szN array where
                        sz1,...,szN indicate the size of each dimension. For
                    example, randi(10,3,4) returns a 3-by-4 array of random
                    integers between 1 and 10.
X = randi(s,___)s instead of the
                    default global stream. To create a stream, use RandStream. You can specify s
                    followed by any of the input argument combinations in previous syntaxes.
Examples
Input Arguments
Output Arguments
More About
Tips
- The sequence of numbers produced by - randiis 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 - randican contain repeated integer values. This behavior is sometimes referred to as sampling with replacement. Use- randpermif you require all unique values.
- If - iminand- imaxare outside the range of the output type (as specified by- typenameor by the prototype- p), then- randifirst creates random integers within the interval- [imin,imax]and converts any resulting out-of-range integers to the minimum or maximum value of the output type. For example:- rng default; r = randi([-10 10],1,10) - r = 7 9 -8 9 3 -8 -5 1 10 10- rng default; r = randi([-10 10],1,10,"logical") - r = 1×10 logical array 1 1 0 1 1 0 0 1 1 1 
Extended Capabilities
Version History
Introduced in R2008bSee Also
rand | randn | rng | RandStream | randperm