Generate random non-repeating integers from a small range

后端 未结 5 767
慢半拍i
慢半拍i 2020-12-10 08:16

What I\'m trying to accomplish is the following:

I wish to create a vector of integers, from a relatively small range, and ensure that none of the integers will be f

5条回答
  •  星月不相逢
    2020-12-10 08:59

    you can use the following code for generate Non Repeating Random Numbers from 1 to M

    randperm(M);

    and for K Non Repeating Random Numbers from 1 to M

    randperm(M, K);

    enjoy

提交回复
热议问题