using a seed for normal random number
32 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!