Random selection

前端 未结 4 1796
长发绾君心
长发绾君心 2020-12-21 00:20

Given two integer numbers N and n (N >= n > 0), how do I generate random selection (without repetition!) of [0, N) with length = n? E.g. Given N = 5, n = 3 possible solution

4条回答
  •  粉色の甜心
    2020-12-21 01:20

    Divide the interval [0,N] to n intervals. From each interval select a random number and then randomize the result. The problem is that in this situation the the distribution is not uniformed.

提交回复
热议问题