What 0 represents in rand function?

15 views (last 30 days)
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 Comments
SRI
SRI on 26 Jun 2014
Hi
Did you try typing this command in matlab,since it outperform no result
subha
subha on 26 Jun 2014
Edited: subha on 26 Jun 2014
yes i tried by typing. i got same. thats why to clarify i posted here

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 26 Jun 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 Comments
subha
subha on 8 Jul 2014
When i typed, rng(0)and x= rand(1,5), every time i run, i get same random values. But if i type rng('shuffle') and then x=rand(1,5), it provides different random numbers each time. I understand this from your statement as well as from documents. If i use both, for example rng(0) and rng('shuffle') and then x=rand(1,5), i guess rng('shuffle') overwrites rng(0). it means, i will get different sequence of numbers every time. Am i right?
Geoff Hayes
Geoff Hayes on 9 Jul 2014
Yes. Because you call rng('shuffle') after rng(0) there will be a different sequence of numbers.

Sign in to comment.

More Answers (0)

Categories

Find more on Random Number Generation in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!