Algorithm to select a single, random combination of values?

后端 未结 7 1021
傲寒
傲寒 2020-11-22 14:04

Say I have y distinct values and I want to select x of them at random. What\'s an efficient algorithm for doing this? I could just call rand(

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 14:47

    A little suggestion: if x >> y/2, it's probably better to select at random y - x elements, then choose the complementary set.

提交回复
热议问题