I'm trying to generate random numbers between zero and 1 using fix(clock) but I'm having difficulties, each time I run the program I get the same numbers. Can someone please help?
1 次查看(过去 30 天)
显示 更早的评论
MinSec=fix(clock);
seed=100*MinSec(5)+MinSec(6);
D=seed;
a=777;
b=1444;
c=6666;
k=1:55;
D(k)=(a*D+b)*mod(c,k);
D_max=max(D(k));
R(k)=D(k)/D_max;
It was recommended that I use a while loop but I only generated one number with that.
0 个评论
采纳的回答
Azzi Abdelmalek
2013-3-3
Because mod(c,k) is a constant vector and a*D+b is a variable scalar
k*v/max(k*v)=k*v/(k*max(v))=v/max(v) which is a constant because v is a constant
1 个评论
Azzi Abdelmalek
2013-3-3
编辑:Azzi Abdelmalek
2013-3-3
Try this
D(k)=(a*c+b)*mod(seed,k)
instead of D(k)=(a*D+b)*mod(c,k);
更多回答(2 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Random Number Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!