what is the equivalent script to TWISTER('state')

조회 수: 2 (최근 30일)
wangm
wangm 2021년 10월 29일
답변: Deepak Gupta 2021년 10월 29일
I have a old matlab using S = TWISTER('state') which return a 625-element vector of UINT32 values containing the current state of the uniform generator.
If I simple change it to s = rng; then I got a structure s has type (twister), seed and State (625x1 unit32). does S means s.State?
I know if I use the same seed, I will get the same random number. but I do not know where Matlab uses the output State (a 625X1 array)?

답변 (2개)

Chris
Chris 2021년 10월 29일
편집: Chris 2021년 10월 29일
Yes, s.State for the default rng should be equivalent to S.
The values in the state are used in the Twister algorithm to generate the pseudorandom numbers.
Here's a bit more info on the changes in Matlab (though it's maybe not what you are looking for)
The functions rand, randi, etc appear to pull numbers from a RandStream.

Deepak Gupta
Deepak Gupta 2021년 10월 29일
Yes, you are right. I can't see what twister does in my version of matlab. But Twister is basically a random number generator.
rng is a function which lets you choose a generator and set seed for it . Default Generator for rng is Twister but you can change it to other generators as well.
"The third field of the struct, State, contains a copy of the generator's current state vector. This state vector is the information that the generator maintains internally in order to generate the next value in its sequence of random numbers. Each time you call rand, randi, or randn, the generator that they share updates its internal state. Thus, the state vector in the settings structure returned by rng contains the information necessary to repeat the sequence, beginning from the point at which the state was captured." From rng help page.
Go through the the rng help:

카테고리

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

제품


릴리스

R2011b

Community Treasure Hunt

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

Start Hunting!

Translated by