vendredi 17 novembre 2017

Random number with 1/x distribution? [duplicate]

This question already has an answer here:

Let say I have sorted array :

 ary = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]

the goal is to randomly pick a number with HIGHER probability of selecting lower numbers. One way to do that is the following :

 ary[ int( rand() * rand() * 10) ]

or even :

 ary[ int( rand() * rand() * 11) ]

multiplying random numbers 0 < x < 1, on average will produce smaller numbers.

I was wondering if you know better more robust way to that ? Perfectly the "probability slope" of the chance of selecting number should approximate something like 1/x function or something like that.

1/x




Aucun commentaire:

Enregistrer un commentaire