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?

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.

 採用された回答

Azzi Abdelmalek
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
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 件)

Marco
Marco 2013 年 3 月 3 日
thank you for your response, it works better than before. The numbers still express a pattern but their not the same as before.
Marco
Marco 2013 年 3 月 3 日
I made one correction. Because k is still small compared to seed, I changed it to mod(seed,50*k). The results are uniform.

カテゴリ

ヘルプ センター および File Exchange で Random Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by