rng function in matlab

조회 수: 2 (최근 30일)
Yanay Dado
Yanay Dado 2021년 4월 22일
답변: Steven Lord 2021년 4월 22일
Hi, I have 3 question about the rng function in matlab:
  1. what is porpuse of the state field?
  2. what does legacy type mean?
  3. what does 'shuffle' mean?
thanks/
  댓글 수: 2
Scott MacKenzie
Scott MacKenzie 2021년 4월 22일
Have you tried
>> doc rng
The answers to your questions are in the documentation.
Yanay Dado
Yanay Dado 2021년 4월 22일
Yes. But Mathworks does not elaborate much about it, so I am asking here about what remained unclear

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

답변 (1개)

Steven Lord
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
ans = logical
1
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.

카테고리

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