what is the use of seed.
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
(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 comentarios
Respuestas (1)
Wayne King
el 27 de Nov. de 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 comentarios
Walter Roberson
el 27 de Nov. de 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.
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!