在java中制作非均匀概率分布 [英] making non-uniform probability distribution in java
本文介绍了在java中制作非均匀概率分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个java类中总共没有元素(比如500个),这将生成3个差异类型(类型A,类型B和类型C)的对象,概率为A=0.3,B=0.2,C=0.5.我找不到一个好的和简单的解决方案,任何人都可以帮助我提供示例代码或一些参考
i am having total no of elements(say 500) in a java class, which will generate a population of 3 diff type (type A,Type B and Type C) of objects with a probability of A=0.3,B=0.2,C=0.5. i am not able to find a nice and easy solution ,can any one help me with a sample code or some reference
提前致谢
推荐答案
对于每个元素,生成一个 0 到 9 之间的随机 int r.
For each element, generate a random int r between 0 and 9.
If 0 <= r < 3 then Type A.
If 3 <= r < 5 then Type B.
If 5 <= r < 10 then Type C.
这篇关于在java中制作非均匀概率分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文