by gnramires · 2y ago · 0 comments
If I may suggest another algorithm, something like picking from most popular to least with probability ~1/(rank+k)^p, where p is any number >1, for example set p=1.5, k=10.
It can be implemented the following way (by computing the integral of the probability distribution):
(1) Have sorted index by popularity with n items
(2) Pick a random (double) r between 0 and 1
(3) The chosen index is (if I did my integrals right;round to nearest integer):
i = ( k^(p-1)*(n-1+k)^(p-1) / ( (r+1)*(n-1+k)^(p-1) - r*k^(p-1) ) ) ^ 1/(p-1) - k
I've got an expression (after correcting my rusty maths) of
i = k*(n-1+k) / ( (1-r)*(n-1+k)^(p-1) + r*k^(p-1) ) ^ (1/(p-1)) - k
I think there could be precision problems (with p<2 specially)