Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Non continous range random number generation

1 Ansicht (letzte 30 Tage)
Muhammad
Muhammad am 24 Apr. 2013
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Hi, I want to generate a random integer vector of range 1 to 10. The vector must contain all random integers in range except for 1 and 4. Regards, Muhammad Waqar Ahmed
  1 Kommentar
Mahdi
Mahdi am 24 Apr. 2013
Do you want to generate just one random number from 1 to 10? Or what is the length of the vector that you want to produce?

Antworten (2)

Walter Roberson
Walter Roberson am 24 Apr. 2013
V = [2, 3, 5, 6, 7, 8, 9, 10];
randV = V(randperm(length(V)));
  3 Kommentare
Muhammad
Muhammad am 25 Apr. 2013
How about if i want to generate one number at a time?
Walter Roberson
Walter Roberson am 25 Apr. 2013
V = [2, 3, 5, 6, 7, 8, 9, 10];
randV = V(randi(length(V)));

Mahdi
Mahdi am 24 Apr. 2013
If you have the statistics toolbox, you can use the following idea:
randsample([2 3 5 6 7 8 9 10], 5, 1)
This produces 5 random numbers from the set, with replacement.

Community Treasure Hunt

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

Start Hunting!

Translated by