필터 지우기
필터 지우기

What 0 represents in rand function?

조회 수: 6 (최근 30일)
subha
subha 2014년 6월 26일
댓글: Geoff Hayes 2014년 7월 9일
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
SRI
SRI 2014년 6월 26일
Hi
Did you try typing this command in matlab,since it outperform no result
subha
subha 2014년 6월 26일
편집: subha 2014년 6월 26일
yes i tried by typing. i got same. thats why to clarify i posted here

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
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
subha
subha 2014년 7월 8일
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 2014년 7월 9일
Yes. Because you call rng('shuffle') after rng(0) there will be a different sequence of numbers.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by