Uniformly distributed pseudorandom integers
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
.
X = randi(
generates integers from random number stream s
,___)s
instead of the
default global stream. To create a stream, use RandStream
. Specify s
followed by
any of the argument combinations in previous syntaxes, except for the ones that
involve 'like'
. This syntax does not support the
'like'
input.
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.
rand
| randn
| randperm
| RandStream
| rng