How to do weighted random sample of categories in python

后端 未结 9 2135

Given a list of tuples where each tuple consists of a probability and an item I\'d like to sample an item according to its probability. For example, give the list [ (.3, \'a\'),

9条回答
  •  再見小時候
    2021-01-31 18:20

    Howabout creating 3 "a", 4 "b" and 3 "c" in a list an then just randomly select one. With enough iterations you will get the desired probability.

提交回复
热议问题