我想根据分布式概率生成一个数字.例如,只是说每个数字都有以下几种:
Number| Count
1 | 150
2 | 40
3 | 15
4 | 3
with a total of (150+40+15+3) = 208
then the probability of a 1 is 150/208= 0.72
and the probability of a 2 is 40/208 = 0.192
Run Code Online (Sandbox Code Playgroud)
如何根据此概率分布创建一个返回数字的随机数生成器?
我很高兴现在基于静态的硬编码集,但我最终希望它从数据库查询中获得概率分布.
我见过像类似的例子这一个 ,但他们都不是很普通的.有什么建议?