using a seed for normal random number
20 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Peter Perkins
2013-3-21
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sources 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!