%% Random Number Generator Using Substreams
% For some generator types, you can create different substreams from a random stream. Values generated from different substreams are mutually independent.
% For instance, create a random number stream using a combined multiple recursive generator.

s = RandStream('mrg32k3a');

% To reposition a stream to a particular substream, set its Substream property. For instance, generate random numbers in a loop. Position the random number stream to the beginning of a different substream before each iteration of the loop. Generate 3 mutually independent sets of 5 random numbers.

for i = 1:3
    s.Substream = i;
    z = rand(s,1,5)
end

% To reproduce the second set of 5 random numbers, reposition the stream to the corresponding substream.

s.Substream = 2;
z = rand(s,1,5)

%
% Copyright 2020 The MathWorks, Inc.