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

42 views (last 30 days)
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 Comments

Sign in to comment.

Accepted Answer

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

More Answers (0)

Categories

Find more on Random Number Generation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by