What 0 represents in rand function?
조회 수: 6 (최근 30일)
이전 댓글 표시
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
채택된 답변
Geoff Hayes
2014년 6월 26일
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
Geoff Hayes
2014년 7월 9일
Yes. Because you call rng('shuffle') after rng(0) there will be a different sequence of numbers.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!