Generate random numbers with fix probability

后端 未结 4 1455
萌比男神i
萌比男神i 2021-01-01 03:15

I red a lot in the forum about this, but all answers were so specific to the the asked question. The nearest one I found to my need was:Probability Random Number Generator b

4条回答
  •  Happy的楠姐
    2021-01-01 03:46

    In your case you might generate random from 1 to 100 and then:

    if random in 1:40 -> face 1
    elseif random in 41:50 -> face 2
    and so on. 
    

    Of course, real code would be a little more complex to get real ranges and not hardcoded ifs

提交回复
热议问题