what is the use of seed.
8 ビュー (過去 30 日間)
古いコメントを表示
(1)
for k=1:3
rand('seed',k);
a=rand(1,5)
end
or (2)
for k=1:3
rand(k);
a=rand(1,5)
end
what is the difference between above two command.
0 件のコメント
回答 (1 件)
Wayne King
2011 年 11 月 27 日
(1) is seeding the random number generator so that it produces a predictable sequence of "random" numbers.
For example, if you run the following loop again and again
for k = 1:3
rand('seed',k);
a = rand(5,1),
end
you will get the same 3 vectors for the variable, a.
In (2), rand(k) is producing a kxk matrix of uniform random numbers, then producing a 1x5 vector of uniform random numbers. So I'm not sure what the point of (2) is.
3 件のコメント
Walter Roberson
2011 年 11 月 27 日
Seeding in a loop is seldom desirable, and can often reduce randomness, and is not an acceptable mechanism for security. There have been successful attacks against systems that used seeding in a loop to try to implement security.
Seeding _before_ a loop can be useful.
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!