using a seed for normal random number

30 views (last 30 days)
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

Accepted Answer

Peter Perkins
Peter Perkins on 21 Mar 2013
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.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!