what is the use of seed.
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
(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 Kommentare
Antworten (1)
Wayne King
am 27 Nov. 2011
(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 Kommentare
Walter Roberson
am 27 Nov. 2011
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.
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!