更新时间:2022-11-22 11:06:58
遍历,并为每个元素进行选择的概率=(需要数/数左)
Iterate through and for each element make the probability of selection = (number needed)/(number left)
所以,如果你有40个项目,首先将有机会5/40被选中的。如果是,下一个具有4/39机会,否则它有一个5/39机会。到时候你到了最后,你将有你的5个项目,往往你必须所有的人都在那之前。
So if you had 40 items, the first would have a 5/40 chance of being selected. If it is, the next has a 4/39 chance, otherwise it has a 5/39 chance. By the time you get to the end you will have your 5 items, and often you'll have all of them before that.