Info
此问题已关闭。 请重新打开它进行编辑或回答。
Non continous range random number generation
2 次查看(过去 30 天)
显示 更早的评论
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
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
2013-4-24
V = [2, 3, 5, 6, 7, 8, 9, 10];
randV = V(randperm(length(V)));
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.
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!