cumulative weights in random.choices cumulative weights in random.choices python-3.x python-3.x

cumulative weights in random.choices


The total weight is 10+5+30+5=50.

Suppose the population is [1,2,3,4].

It returns 1 with probability 10/50 = 0.2

It returns 2 with probability 5/50 = 0.1

It returns 3 with probability 30/50 = 0.6

It returns 4 with probability 5/50 = 0.1