Random boolean with weight or bias

前端 未结 8 722
鱼传尺愫
鱼传尺愫 2020-12-01 23:42

I need to generate some random booleans. However I need to be able to specify the probability of returning true. As a results doing:

private R         


        
8条回答
  •  没有蜡笔的小新
    2020-12-02 00:04

    The MockNeat library implements this feature.

    Example for generating a boolean value that has 99.99% of being true:

    MockNeat m = MockNeat.threadLocal();
    boolean almostAlwaysTrue = m.bools().probability(99.99).val();
    

提交回复
热议问题