%% Save and Restore the Generator Settings
%% Section 1
% First, initialize the random number generator to make the results in this example repeatable.

rng(1,'twister');

%
% Save the generator settings in a structure s.

s = rng;

%
% Create an array of random integer values between 1 and 10.

A = randi(10,3,3)

%
% Repeat the same command.

A = randi(10,3,3)

% The first call to randi changed the state of the generator, so the second result is different.
%
% Now, return the generator to the original state stored in s and reproduce the first array A.

rng(s);
A = randi(10,3,3)

% Unlike reseeding, which reinitializes the generator, this approach allows you to save and restore the generator settings at any point.
% Copyright 2012 The MathWorks, Inc.