Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Non continous range random number generation

조회 수: 1 (최근 30일)
Muhammad
Muhammad 2013년 4월 24일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Mahdi
Mahdi 2013년 4월 24일
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?

답변 (2개)

Walter Roberson
Walter Roberson 2013년 4월 24일
V = [2, 3, 5, 6, 7, 8, 9, 10];
randV = V(randperm(length(V)));
  댓글 수: 3
Muhammad
Muhammad 2013년 4월 25일
How about if i want to generate one number at a time?
Walter Roberson
Walter Roberson 2013년 4월 25일
V = [2, 3, 5, 6, 7, 8, 9, 10];
randV = V(randi(length(V)));

Mahdi
Mahdi 2013년 4월 24일
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