- computers can't really generate random numbers.
- that is exactly what MATLAB is specified to do:
Why does MATLAB generate identical random values after re-opening the program?
4 次查看(过去 30 天)
显示 更早的评论
I run the code below
y = rand(1,5)
and I get the following values:
0.8147 0.9058 0.1270 0.9134 0.6324
I close MATLAB and reopen it again and enter the same code and I get the same random values. Why does MATLAB create the exact same numbers each time?
1 个评论
采纳的回答
Rightia Rollmann
2018-7-24
2 个评论
Guillaume
2018-7-24
Follow the link in Stephen's comment to get the answer to your question, or do what Madhan told you.
Also, don't use the answer box for comments.
Stephen23
2018-7-25
编辑:Stephen23
2018-7-25
"I set rng to 'default', so I expected that it'll generate new random numbers after re-running MATLAB..."
The rng documentation explains that the 'default' option as "This way, the same random numbers are produced as if you restarted MATLAB. The default settings are the Mersenne Twister with seed 0." Clearly with the same seed it will generate exactly the same values each time. That is what it is specified to do!
更多回答(1 个)
madhan ravi
2018-7-24
编辑:madhan ravi
2018-7-24
hi, see the link below:
https://www.mathworks.com/help/matlab/ref/rng.html
另请参阅
类别
在 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!