How to generate unique random integers between 1 to n (with no possibility of Sequence)
1 次查看(过去 30 天)
显示 更早的评论
I have alread tryed randperm(5)
But unfortunately after try again and again at one stage it produced random numbers 1 2 3 4 5
how to resolve this problem.
0 个评论
回答(2 个)
James Tursa
2021-6-11
编辑:James Tursa
2021-6-11
If 1:n is the only sequence you don't want, just use randperm(n) and reject the one case you don't want. I.e., if you get it then re-generate another case.
3 个评论
James Tursa
2021-6-11
Why isn't it a solution? Why can't you have logic to check and re-generate another?
另请参阅
类别
在 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!