randi
Uniformly distributed pseudorandom integers
Syntax
Description
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
indicate 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 array of pseudorandom integers between typename
)1
and
imax
of data type typename
. The
typename
input can be "single"
,
"double"
, "int8"
,
"uint8"
, "int16"
,
"uint16"
, "int32"
, or
"uint32"
. You can use any of the input arguments in the
previous syntaxes.
X = randi(
generates integers from random number stream 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
Tips
The sequence of numbers produced by
randi
is determined by the internal settings of the uniform pseudorandom number generator that underliesrand
,randi
, andrandn
. You can control that shared random number generator usingrng
.The arrays returned by
randi
can contain repeated integer values. This behavior is sometimes referred to as sampling with replacement. Userandperm
if you require all unique values.
Extended Capabilities
Version History
Introduced in R2008bSee Also
rand
| randn
| rng
| RandStream
| randperm