How to generate same set of random numbers?

20 ビュー (過去 30 日間)
Will Smith
Will Smith 2016 年 10 月 12 日
コメント済み: Walter Roberson 2021 年 7 月 13 日
How to generate same set of random numbers time and again?

採用された回答

Abhishek Jain
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..!!
  1 件のコメント
Will Smith
Will Smith 2016 年 10 月 12 日
Thank you for the quick response.

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2016 年 10 月 12 日
See rng() if you are using a reasonably recent MATLAB.
  1 件のコメント
Will Smith
Will Smith 2016 年 10 月 12 日
Thank you for the quick response.

サインインしてコメントする。


Yaxuan Li
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
Walter Roberson 2021 年 7 月 13 日
You need to reset the seed.
rng(1,'twister');
x = rand(1,5)
x = 1×5
0.4170 0.7203 0.0001 0.3023 0.1468
rng(1,'twister');
x = rand(1,5)
x = 1×5
0.4170 0.7203 0.0001 0.3023 0.1468

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by