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)
Show older comments
Mohd Helmi Mansor on 21 Mar 2019
Commented: Guillaume on 21 Mar 2019
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?
Guillaume on 21 Mar 2019
Why not generate a number between 1 and 10 and if it's 3 or 6 retry? Seems simple enough.
Thorsten on 21 Mar 2019
x = setdiff(1:10, [3, 6]);
r = x(randi(numel(x)));
More Answers (0)
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!