Array of random integers
R = randi(
valrange
,sz,arraytype
)
R = randi(valrange
,sz,datatype
,arraytype
)
R = randi(valrange
,sz,'like',P)
R = randi(valrange
,sz,datatype
,'like',P)
C = randi(valrange
,sz,codist)
C
= randi(valrange
,sz,datatype
,codist)
C = randi(valrange
,sz,___,codist,'noCommunication')
C = randi(valrange
,sz,___,codist,'like',P)
R = randi(
creates a matrix with underlying class of double, with valrange
,sz,arraytype
)randi
integer values in all elements.
R = randi(
creates a matrix with underlying class of valrange
,sz,datatype
,arraytype
)datatype
, with
randi
values in all elements.
The size and type of array are specified by the argument options according to the following table.
Argument | Values | Descriptions |
---|---|---|
valrange | max or [min
max] | Specifies integer value range from 1 to
max , or from min to
max .. |
sz | n | Specifies size as an n -by-n
matrix. |
m,n or [m n] | Specifies size as an m -by-n
matrix. | |
m,n,...,k or [m n ...
k] | Specifies size as an
m -by-n -by-...-by-k
array. | |
arraytype | 'distributed' | Specifies distributed array. |
'codistributed' | Specifies codistributed array, using the default distribution scheme. | |
'gpuArray' | Specifies gpuArray. | |
datatype | 'double' (default),
'single' , 'int8' ,
'uint8' , 'int16' ,
'uint16' , 'int32' ,
'uint32' , 'int64' , or
'uint64' | Specifies underlying class of the array, i.e., the data type of its elements. |
R = randi(
creates an array of valrange
,sz,'like',P)randi
values with the same type and
underlying class (data type) as array P
.
R = randi(
creates an array of valrange
,sz,datatype
,'like',P)randi
values with the specified underlying
class (datatype
), and the same type as array
P
.
C = randi(
or
valrange
,sz,codist)C
= randi(
creates a codistributed array of valrange
,sz,datatype
,codist)randi
values with the specified
size and underlying class (the default datatype
is
'double'
). The codistributor object codist
specifies the distribution scheme for creating the codistributed array. For
information on constructing codistributor objects, see the reference pages for
codistributor1d
and codistributor2dbc
. To use the
default distribution scheme, you can specify a codistributor constructor without
arguments. For example:
spmd C = randi(8,codistributor1d()); end
C = randi(
specifies that no interworker communication is to be performed when constructing a
codistributed array, skipping some error checking steps. valrange
,sz,___,codist,'noCommunication')
C = randi(
creates a codistributed array of valrange
,sz,___,codist,'like',P)randi
values with the specified
range, size, underlying class, and distribution scheme. If either the class or
codistributor argument is omitted, the characteristic is acquired from the
codistributed array P
.
Create a 1000-by-1000 distributed array of randi
values
from 1 to 100, with underlying class double:
D = randi(100,1000,'distributed');
Create a 1000-by-1000 codistributed double matrix of randi
values from 0 to 12, distributed by its second dimension (columns).
spmd(4) C = randi([0 12],1000,'codistributed'); end
With four workers, each worker contains a 1000-by-250 local piece of
C
.
Create a 1000-by-1000 codistributed single
matrix of
randi
values from 1 to 4, distributed by its columns.
spmd(4) codist = codistributor('1d',2,100*[1:numlabs]); C = randi(4,1000,1000,'single',codist); end
Each worker contains a 100-by-labindex
local piece of
C
.
Create a 1000-by-1000 gpuArray of randi
values from
—50 to 50, with underlying class double
:
G = randi([-50 50],1000,'double','gpuArray');