set the state for the random number generator
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
jack
am 31 Mär. 2011
Kommentiert: Steven Lord
am 21 Mai 2018
For the function "randn", one can use
randn('state',100);
to set the state.
How about the generator "*poissrnd*"?
2 Kommentare
Akzeptierte Antwort
the cyclist
am 1 Apr. 2011
Bearbeitet: John Kelly
am 2 Mär. 2015
If you are using an older version of MATLAB, then setting the state for rand (rather than randn) will set the state for poissrnd as well.
However, if you are using a relatively new version of MATLAB, the preferred method is to set the random number stream via RandStream:
stream = RandStream('mt19937ar','Seed',28);
RandStream.setDefaultStream(stream);
where you should put some integer where I put "28".
You can read more in the help file for RandStream, or lots more detail here: http://www.mathworks.com/help/matlab/ref/randstream.html.
I believe all the random number generators work off of the stream, but I am not 100% sure of that. I did verify that I got the same sequence of numbers from poissrnd after setting the seed like this.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Random Number Generation 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!