MATLAB: Using a seed for normal random number

MATLABsimulation

Hi,
I am using the following code in a simulation. I need to use a seed to generate the same random numbers. can you please help me with it?
thanks
a0 = 0.1; a1 = 0.4;
epsi=zeros(3000,1);
simsig=zeros(3000,1);
for i = 1:3000
if (i==1)
simsig(i) = a0/(1-a1) ;
s=(simsig(i))^0.5;
epsi(i) = normrnd(0,1) * s;
else
simsig(i) = a0+ a1*(epsi(i-1))^2;
s=(simsig(i))^0.5;
epsi(i) = normrnd(0,1) * s;
end
end

Best Answer

dav, as long as you're using a fairly recent version of MATLAB, the rng function is what you want to use. For reproduceability, you can probably just use something like
rng(seed)
but this page
describes a whole set of scenarios.