Obtaining same values at avery simulation using rand function
1 回表示 (過去 30 日間)
古いコメントを表示
I'm building some simulations with matlab and I use rand function. I would obtain at every run, the same results. I read somewhere I have to set the seed of rand function. I tried using
s = RandStream('mcg16807', 'seed', 0)
RandStream.setGlobalStream(s);
but it didn't work.Maybe I made some mistake.
0 件のコメント
採用された回答
Wayne King
2012 年 9 月 14 日
I think you should use the newer rng
rng default;
x = randn(100,1);
rng default
y = randn(100,1);
max(abs(x-y))
x and y are the same sequence.
In general, you can capture the random generator settings and resuse them
S = rng;
x = randn(100,1);
rng(S)
y = randn(100,1);
0 件のコメント
その他の回答 (2 件)
Oleg Komarov
2012 年 9 月 14 日
編集済み: Oleg Komarov
2012 年 9 月 14 日
You can use rng()
rng(1)
rand(1,5)
rng(1)
rand(1,5)
Or with your approach:
s = RandStream('mcg16807', 'seed', 0);
RandStream.setGlobalStream(s);
rand(1,5)
s = RandStream('mcg16807', 'seed', 0);
RandStream.setGlobalStream(s);
rand(1,5)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Fuzzy Logic Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!