How to select random numbers in a range, but weight them to a part of the range? (in Java)

I want to choose a random number from a series of numbers, but I want to weight part of the range For example:

>Select a random number between 1-10 > weight so that 1-5 may be 20% more likely than 6-10

Is that possible? What shall I do?

Solution

It depends on what you want the probability distribution to look like

For example:

Pick a random number between 1-10
If it is <= 6
    Return a random number between 1-5
Else
    Return a random number between 6-10
EndIf

Dial a number 60% of the time and 6-10% of the time

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>