rng function in matlab
2 次查看(过去 30 天)
显示 更早的评论
Hi, I have 3 question about the rng function in matlab:
- what is porpuse of the state field?
- what does legacy type mean?
- what does 'shuffle' mean?
thanks/
2 个评论
Scott MacKenzie
2021-4-22
Have you tried
>> doc rng
The answers to your questions are in the documentation.
回答(1 个)
Steven Lord
2021-4-22
what is porpuse of the state field?
It is the state of the random number generator. For most users of rng you can ignore what the elements of the state represents and just know what if you call rng with the same inputs (except for 'shuffle') it will reset the random number generator to the same condition, allowing it to generate the same numbers.
rng(1, 'twister')
x1 = rand(1, 10);
rng(1, 'twister')
x2 = rand(1, 10);
isequal(x1, x2) % true
If the output of rng was a machine it likely would be labeled "No user-serviceable parts inside".
what does legacy type mean?
The legacy random number generators are generators that were the defaults in older releases. Unless you're trying to reproduce the same results as were generated in those older releases you should probably use the newer generators. From the table in the "Choosing a Random Number Generator" section on this documentation page you can see that the legacy generators tend to have a much smaller period before they repeat and/or they have other characteristics that make them not the best choices.
what does 'shuffle' mean?
Use 'shuffle' when you want the random number generator to be in some arbitrary state but you don't care what state. The name is meant to evoke a deck of cards: if you're playing a game you don't really care what order the deck is in, but you don't want it to be stacked Ace through King of one suit, then A through K of the next suit, etc. So you give it a couple quick shuffles and call it good.
Calling rng(fixedSeed, generator) is like a magician shuffling the deck in a specific way to put it in a fixed order that they know ahead of time. This allows them to perform their card trick and get the same result each performance.
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!