How to generate same set of random numbers?
11 次查看(过去 30 天)
显示 更早的评论
How to generate same set of random numbers time and again?
0 个评论
采纳的回答
Abhishek Jain
2016-10-12
You can control random number generation using 'rng()' function. The usage is rng(seed).
rng(seed) seeds the random number generator using the nonnegative integer seed so that rand, randi, and randn produce a predictable sequence of numbers.
Hope that helps..!!
更多回答(2 个)
Yaxuan Li
2021-7-13
编辑:Walter Roberson
2021-7-13
Why this doens't work for me?
rng(1,'twister');
x = rand(1,5)
x =
0.4170 0.7203 0.0001 0.3023 0.1468
x = rand(1,5)
x =
0.0923 0.1863 0.3456 0.3968 0.5388
1 个评论
Walter Roberson
2021-7-13
You need to reset the seed.
rng(1,'twister');
x = rand(1,5)
rng(1,'twister');
x = rand(1,5)
另请参阅
类别
在 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!