What does command 'rng default;' do?
341 views (last 30 days)
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.
You can read more here: http://www.mathworks.com/help/matlab/ref/rng.html