Code covered by the BSD License  

Highlights from
initialize normal random number generator

from initialize normal random number generator by Phillip M. Feldman
sets the state for Matlab's normal (Gaussian) random number generator

initrandn(seed)
function seed= initrandn(seed)
%
% initrandn() sets the state for Matlab's normal (Gaussian) random number
% generator. (Matlab has two generators-- 'rand' and 'randn'-- for uniform
% and normal random numbers, respectively.  Each of these maintains its own
% state).
%
% If the optional calling argument is missing, initrandn() prompts the user
% to enter a seed interactively.  If the optional calling argument is
% present but is an empty matrix, or if the user input is empty, a default
% seed is generated based on the current date and time.

% Generate a default initial seed by taking the dot-product of a constant
% vector and the transpose of the clock vector (this converts the clock
% vector into a large integer):

def= floor( [1 30*24*60*60 24*60*60 60*60 60 1] * clock' );

% If the calling argument is missing, prompt the user to specify a seed:

if (nargin == 0)
   prompt= '\nInitial seed (integer) for random number generator: ';
   seed= input(prompt);
end

if (isempty(seed))
   fprintf('Using default seed derived from current date/time: %d\n', def);
   seed= def;
end

randn('state', seed);

Contact us at files@mathworks.com