How to generate same set of random numbers?
조회 수: 33 (최근 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!