making non-uniform probability distribution in java

核能气质少年 提交于 2019-12-13 08:59:58

问题


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

Thanks in advance


回答1:


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.


来源:https://stackoverflow.com/questions/14183948/making-non-uniform-probability-distribution-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!