How to avoid duplicate random value when open multiple matlab session ?

1 回表示 (過去 30 日間)
Tuong Nguyen Minh
Tuong Nguyen Minh 2020 年 8 月 16 日
コメント済み: Mehmed Saad 2020 年 8 月 17 日
Currently I need to open 10 diffierent matlab session simultaneously using a .bat file. In these 10 sessions, i need to generate random number uniformly distributed on the interval 0.25 to 0.5. From what I observe there were a lot of duplication of my random number from these 10 matlab session. My guess is that because they are open simultaneously using the bat file and my interval is quite short, the random seed somehow does not change much.
I am using the rand function to generate random real number
Please help me with this issue. Thank you !

採用された回答

Mehmed Saad
Mehmed Saad 2020 年 8 月 16 日
add this in your code
seed = randi(2020);
rng(seed)
  2 件のコメント
Tuong Nguyen Minh
Tuong Nguyen Minh 2020 年 8 月 16 日
Does this work for rand because i am not using randi ?
Mehmed Saad
Mehmed Saad 2020 年 8 月 17 日
this code is just for generating random seed. everytime your code is called, a new seed is called hence generating a different random numbers. add your code of random number after this code
For example
seed = randi(2020);% Genrates random number bw 1 and 2020
rng(seed) % control random numbers from here onwards with rng
% Your code containing random number. it is prefferable if you add these two lines at the start of code

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by