%% Capture and Restore Generator Settings
% Capture the generator settings, generate an array of random numbers, and then restore the generator to the initial settings to create predictable arrays of random numbers.
%
% Save the current state of the random number generator.

state = tallrng

%
% Create a tall array of random numbers using arrayfun.

t = tall(zeros(10,1));
n1 = arrayfun(@(x) x+randn, t)

%
% Restore the generator to the previous state and regenerate the array of random numbers. The two arrays n1 and n2 are equal.

tallrng(state)
n2 = arrayfun(@(x) x+randn, t)

% Copyright 2012 The MathWorks, Inc.