# Which algorithm is better to control the probability of randomly sampling from an array?

Welcome!

There is such an interesting problem that my programmer something does not overpower:

I have on site (construction site) decided to implement something like your teaser online...

to write it of problems was not, but that's what happened stopper:

the probability of the ad decided to do the work of ctr and price per click entered by the advertiser (for system Google wins the intersection of high click prices and high quality ads)...

But how to effectively and correctly implement this control sample ads, yet could not doperet...

I would be grateful for any advice!!! :)
October 8th 19 at 03:36
October 8th 19 at 03:38
If ad database in MySQL and ads is not very much, it is possible approximately so:
SELECT... ORDER BY ctr*price+RAND()
where x is some ratio
Thanks for the advice! Is this a simple solution?.. - Aaron commented on October 8th 19 at 03:41
By the way, where in this formula is the "x"?? - Aaron commented on October 8th 19 at 03:44
apparently the author missed, should be so ctr*price+x*RAND()
rand() produces random number from 0 to 1, but I think it's not the best solution.
So low ctr*price had at least some chance to be shown the X should be not less than MAX(ctr*price) — MIN(ctr*price), too large X is reduced to minimumu influence the values of ctr*price. I do not think that the best solution, but to some extent it solves the problem. Perhaps this is enough. - modesta25 commented on October 8th 19 at 03:47
October 8th 19 at 03:40
Will allow us to offer heavy mathematical solution:

1) normalization and at the same time defining the boundaries of the RND() for each advertisement: ( LEFT[i]; LEFT[i+1] )

NORM=0
for i=0 to N-1
LEFT[i] = NORM
NORM = NORM + CTR[i]*PRICE[i]

2) work