How can I generate random number between 1 and 10, and at the same time I want to exclude number 3 & 6?

91 ビュー (過去 30 日間)
How can I generate random number between 1 and 10, and at the same time I want to exclude number 3 & 6 using M-file?
  3 件のコメント
Guillaume
Guillaume 2019 年 3 月 21 日
Why not generate a number between 1 and 10 and if it's 3 or 6 retry? Seems simple enough.

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

採用された回答

Thorsten
Thorsten 2019 年 3 月 21 日
x = setdiff(1:10, [3, 6]);
r = x(randi(numel(x)));

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by