User`s guide

6 Programming Overview
6-38
delete(p)
Note Because rng('shuffle') seeds the random number generator based on the
current time, you should not use this command to set the random number stream on
different workers if you want to assure independent streams. This is especially true
when the command is sent to multiple workers simultaneously, such as inside a parfor,
spmd, or a communicating job. For independent streams on the workers, use the default
behavior; or if that is not sufficient for your needs, consider using a unique substream on
each worker.
Client and Workers
By default, the MATLAB client and MATLAB workers use different random number
generators, even if the workers are part of a local cluster on the same machine with
the client. For the client, the default is the Mersenne Twister generator ('twister'),
and for the workers the default is the Combined Multiple Recursive generator
('CombRecursive' or 'mrg32k3a'). If it is necessary to generate the same stream of
numbers in the client and workers, you can set one to match the other.
For example, you might run a script as a batch job on a worker, and need the same
generator or sequence as the client. Suppose you start with a script file named
randScript1.m that contains the line:
R = rand(1,4);
You can run this script in the client, and then as a batch job on a worker. Notice that the
default generated random number sequences in the results are different.
randScript1; % In client
R
R =
0.8147 0.9058 0.1270 0.9134
parallel.defaultClusterProfile('local')
c = parcluster();
j = batch(c,'randScript1'); % On worker
wait(j);load(j);
R
R =
0.3246 0.6618 0.6349 0.6497