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
.
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.
RandStream
| rand
| randn
| randperm
| rng