matlab R2020b randperm fuction is not random

1 回表示 (過去 30 日間)
俊 马
俊 马 2022 年 7 月 14 日
コメント済み: 俊 马 2022 年 7 月 19 日
Hi,
When I use matlab R2020b on linux platform, commands follow:
order = randperm(10)
disp(order)
results show:
6     3     7     8     5     1     2     4     9    10
6     3     7     8     5     1     2     4     9    10
Curiously, the result is fixed,i.e., when I run this script again, the same results appear. Does anybody know what's wrong? thanks
  3 件のコメント
Adam Danz
Adam Danz 2022 年 7 月 14 日
Make sure you're using MATLAB's randperm function by using which
which randperm
built-in (/MATLAB/toolbox/matlab/randfun/randperm)
Does the same result occur if you shuffle the random number generator?
randperm(10)
rng('shuffle')
randperm(10)
俊 马
俊 马 2022 年 7 月 19 日
thanks, it worked

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

採用された回答

Fangjun Jiang
Fangjun Jiang 2022 年 7 月 14 日
Duh! You store the result in "order" and display it again. Of course they are the same!
order = randperm(10)
order = 1×10
5 7 6 10 3 1 4 9 2 8
disp(order)
5 7 6 10 3 1 4 9 2 8
order = randperm(10)
order = 1×10
6 7 5 10 3 8 1 2 9 4
disp(order)
6 7 5 10 3 8 1 2 9 4
  1 件のコメント
Adam Danz
Adam Danz 2022 年 7 月 14 日
Ha! Good catch!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by