Create codistributed array of uniformly distributed pseudo-random numbers
R = codistributed.rand(n)
R = codistributed.rand(m, n, ...)
R = codistributed.rand([m, n, ...])
R = rand(n, codist)
R = rand(m, n, codist)
R = rand([m, n], codist)
R = codistributed.rand(n) creates an n-by-n codistributed array of underlying class double.
R = codistributed.rand(m, n, ...) or R = codistributed.rand([m, n, ...]) creates an m-by-n-by-... codistributed array of underlying class double.
Optional arguments to codistributed.rand must be specified after the required arguments, and in the following order:
classname — Specifies the class of the codistributed array C. Valid choices are the same as for the regular rand function: 'double' (the default), 'single', 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'int64', and 'uint64'.
codist — A codistributor object specifying the distribution scheme of the resulting array. If omitted, the array is distributed using the default distribution scheme. For information on constructing codistributor objects, see the reference pages for codistributor1d and codistributor2dbc.
'noCommunication' — Specifies that no interworker communication is to be performed when constructing the array, skipping some error checking steps.
R = rand(n, codist) is the same as R = codistributed.rand(n, codist). You can also use the optional arguments with this syntax. To use the default distribution scheme, specify a codistributor constructor without arguments. For example:
spmd R = codistributed.rand(8, codistributor1d()); end
R = rand(m, n, codist) and R = rand([m, n], codist) are the same as R = codistributed.rand(m, n, ...) and R = codistributed.rand([m, n, ...]), respectively. You can also use the optional arguments with this syntax.
With four workers,
spmd(4) R = codistributed.rand(1000, codistributor()) end
creates a 1000-by-1000 codistributed double array R, distributed by its second dimension (columns). Each worker contains a 1000-by-250 local piece of R.
spmd(4) codist = codistributor('1d', 2, 1:numlabs); R = codistributed.rand(10, 10, 'uint16', codist); end
creates a 10-by-10 codistributed uint16 array R, distributed by its columns. Each worker contains a 10-by-labindex local piece of R.
When you use rand on the workers in the parallel pool, or in a distributed or parallel job (including pmode), each worker sets its random generator seed to a value that depends only on the labindex or task ID. Therefore, the array on each worker is unique for that job. However, if you repeat the job, you get the same random data.