what is the use of seed.
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
(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 commentaires
Réponses (1)
Wayne King
le 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 commentaires
Walter Roberson
le 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.
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!