What 0 represents in rand function?
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
What rand ('state', 0) is represents. i read in the document, it shows that it is generating random number. Not clear about what state and 0 represents. how can i verify it in matlab?
Also it is mentioned old version follows this way of representation. In new version it is changed. if so how i can represent it in current version. will current version still accept the above line?
2 Commenti
Risposta accettata
Geoff Hayes
il 26 Giu 2014
See this link http://www.mathworks.com/help/matlab/math/updating-your-random-number-generator-syntax.html which discusses the "discouraged" syntaxes of rand, which includes your example of rand('state',0).
From the documentation:
In earlier versions of MATLAB®, you controlled the random number generator used by the rand and randn functions with the 'seed', 'state' or 'twister' inputs...These syntaxes referred to different types of generators, and they will be removed in a future release for the following reasons:
- The terms 'seed' and 'state' are misleading names for the generators.
- All of the former generators except 'twister' are flawed.
- They unnecessarily use different generators for rand and randn.
It goes on to discuss what the intent was behind rand('state',sd), why it was discouraged, and what it should be replaced by.
In your case, the alternative for rand('state',sd) would be rng(sd). It is best to use the recommended alternative as per the note.
You can verify that the original call still does work (though it should be replaced!). In the Command Window type
rand('state',0)
A = rand(100,1);
rand('state',0);
B = rand(100,1);
find((A-B)~=0)
Note that A and B will have the same set of randomly generated numbers, so find((A-B)~=0) will be zero.
4 Commenti
Geoff Hayes
il 9 Lug 2014
Yes. Because you call rng('shuffle') after rng(0) there will be a different sequence of numbers.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Random Number Generation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!