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

3 ビュー (過去 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 Center および File ExchangeRandom Number Generation についてさらに検索

製品


リリース

R2011b

Community Treasure Hunt

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

Start Hunting!

Translated by