Changing the matlab seed

The seed is not changing when I close the Matlab and open a new one. The seed is always being set as 0. How can I fix this?

Respuestas (2)

Bjorn Gustavsson
Bjorn Gustavsson el 21 de Sept. de 2018

0 votos

Your question is a bit on the vague end - but I'll guess that you're asking about the seed for the random number generator...
If that's the case you should take a look at the help for rand, or look for the documentation pages "Updating Your Random Number Generator Syntax". From the former there is a link towards the latter, the latter describes in detail how to randomize the start of the random number sequence...
HTH

4 comentarios

Arvind Ganesh
Arvind Ganesh el 21 de Sept. de 2018
Yes, my question was about random number generator only. The issue is not the syntax.
Say I open two or three new Matlab windows, and execute the command:
rand(2,2)
Then, all 3 windows produce the same output (the output with seed 0 set by command rng(0)). Why is this so? This is not supposed to happen. The seed should change when I close and open a new Matlab window.
Bjorn Gustavsson
Bjorn Gustavsson el 21 de Sept. de 2018
Well that this should or should not happen is a question about design choices and such. I've heard arguments for starting at the same point in the random number stream every time along the line of "if someone wants to test different algorithms with a pseudo-random data-set one should always compare the algorithms with identical data". You can of course put something like rng('shuffle') in your startup.m.
Then you only have to remember that when/if you need to run and rerun multiple algorithms with identical input you'll need to start the random number generator with the same seed.
HTH
Stephen23
Stephen23 el 21 de Sept. de 2018
Editada: Stephen23 el 21 de Sept. de 2018
"This is not supposed to happen. The seed should change when I close and open a new Matlab window."
Yes, it is supposed to happen. This is exactly the documented behavior. In fact this is such a common topic that there is a whole page devoted to explaining this:
That page also explains how to get different random numbers, and is easy to find using any internet search engine.
Arvind Ganesh
Arvind Ganesh el 21 de Sept. de 2018
Thank you. That is helpful.

Iniciar sesión para comentar.

Dennis
Dennis el 21 de Sept. de 2018

0 votos

You can use
rng('shuffle')
For more information have a look here

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 21 de Sept. de 2018

Comentada:

el 21 de Sept. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by