Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
wangm
wangm el 29 de Oct. de 2021
Respondida: Deepak Gupta el 29 de Oct. de 2021
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)?

Respuestas (2)

Chris
Chris el 29 de Oct. de 2021
Editada: Chris el 29 de Oct. de 2021
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 el 29 de Oct. de 2021
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:

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Productos


Versión

R2011b

Community Treasure Hunt

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

Start Hunting!

Translated by