%% Set Global and Local Streams
% Create two random number streams. Set the first stream as a global stream by using RandStream.setGlobalStream.

globalStream = RandStream('mlfg6331_64','NormalTransform','Polar')
RandStream.setGlobalStream(globalStream);

% To show the current global stream, use RandStream.getGlobalStream.

RandStream.getGlobalStream

% Create a second stream myStream that acts separately from the new global stream that you created.

myStream = RandStream('dsfmt19937','NormalTransform','Inversion')

% Generate three random numbers from the global stream. Generate another three random numbers from the local stream myStream that you created.

randn(1,3)
randn(myStream,1,3)

% When you call the functions rand, randn, and randi without myStream, they draw from the global stream, and will not affect the results of calling them with myStream.
%
% Copyright 2020 The MathWorks, Inc.