jeudi 26 mars 2020

A weighted version of random.randint

I would like to choose a random integer between a and b (both included), with the statistical weight of c.

c is a value between a and b.

Which is the most efficient way to apply the weight factor c to random.randint?

The closest I got was this question, but there is a big difference:

I have only one single statistical weight c, not a statistical probability for every value between a and b.

Example:

a = 890
b = 3200

c = 2600

print(random.randint(a,b))

>>>> supposed to result most frequently in a value around 2600

I don't really care about the distribution between a and b, as long as there is a weight on c. However, a Gaussian distribution would be appreciated.




Aucun commentaire:

Enregistrer un commentaire