What does command 'rng default;' do?
367 views (last 30 days)
Show older comments
What is the difference with and without this command?
0 Comments
Answers (1)
jgg
on 23 Feb 2016
Edited: jgg
on 23 Feb 2016
When Matlab generates random numbers, they're not truly random; they are based on a pseudo-random number generating algorithm. The rng command controls the seed, or starting point, for this value. The "default" values resets it to the original value that MATLAB starts with; this evolves over time.
You can see this behaviour if you do something like called rand(10,1), then calling rng('default') then repeating the rand command. It will generate exactly the same "random" numbers.
This is generally useful for situations where you want to repeat an (ex ante) random outcome. For instance, in Monte Carlo simulation or in simulation-based optimization procedures.
3 Comments
Bachtiar Muhammad Lubis
on 20 Dec 2018
so we should call those rng defaut right before the first rand and once again before the second rng default?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!