Advanced use of randi(x) and other random number generating functions
2 次查看(过去 30 天)
显示 更早的评论
Is it possible to get the randi(x) function to work with a specifically chosen set of numbers, such as 1 through 9 except 6?
From what I can tell, the function description doesn't make it seem possible. Is there a creative way around this? What about using other random number generating functions?
0 个评论
采纳的回答
Sean de Wolski
2014-4-18
There's nothing builtin do exclude certain numbers. Of course this is accomplished with a little bit of manipulation:
x=randi(8,[5 5])
x(x>=6) = x(x>=6)+1
randperm might be your friend as well.
0 个评论
更多回答(1 个)
Azzi Abdelmalek
2014-4-18
your_range=[1:5 7:9]
[~,ii]=sort(rand(1,numel(your_range)))
out=your_range(ii)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Random Number Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!