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

19 vues (au cours des 30 derniers jours)
Mohd Helmi Mansor le 21 Mar 2019
Commenté : Guillaume le 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?
##### 3 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Mohd Helmi Mansor le 21 Mar 2019
I want to have one single number from the randomization process (Between 1 & 10). But the number must not be 3 & 6. So it can be either 1,2,4,5,7,8,9 or 10.
Guillaume le 21 Mar 2019
Why not generate a number between 1 and 10 and if it's 3 or 6 retry? Seems simple enough.

Connectez-vous pour commenter.

### Réponse acceptée

Thorsten le 21 Mar 2019
x = setdiff(1:10, [3, 6]);
r = x(randi(numel(x)));
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by