Calculating a jackpot winner based on probabilities Imagine a jackpot where users can bet as much as they want, and each bet increases their winning chance. Given a roll [0-100], how would you calculate the winner?
My solution and the pitfall
To determine winning users, you could check if a drawn roll [0-100] falls between a stack of users' winning probabilities.
Winning probability for each user is calculated by applying Fc(Bet, Pot Size) = Bet * 100 / Pot size.
The only algorithm I have in mind to determine who the winner is, is to perform math server-side and iterate each user's winning probability, and check if roll falls within:
user_bets = [250,250,500]
pot_size = sum(user_bets)
roll = 32.21;
cur_range = [0,0]
for bet in user_bets:
    win_chance = bet * 100 / pot_size
    cur_range = [  cur_range[1] , win_chance + cur_range[1] ]
    if roll &gt;= cur_range[0] and roll &lt;= cur_range[1]:
        # cur_range[0] = 25, cur_range[1] = 50
        # We found the winner
        break

Goal
The goal is to possibly adopt a one-liner algorithm to determine the winner within SQL language, whereas no iteration is involved
Graphic example
User X = BET    =  $13.000
User Y = BET    =   $6.500
User Z = BET    =   $3.250

POT_SIZE        =  $22.750
----------------------------------------------------------------------------------------------------
User X Win range               = 0 -&gt;  57,14     (57% win chance)
User Y Win range               = 57.15 -&gt;  85,71 (29% win chance)
User Z  Win range              = 85,72 -&gt;  100   (14% win chance)
----------------------------------------------------------------------------------------------------
ROLL Example          = 32.27...
WINNER                = User X
----------------------------------------------------------------------------------------------------
ROLL Example          = 91.38...
WINNER                = User Z
For each user, sample the exponential distribution with rate equal to the size of that user's bet. The user with the smallest random variate wins the pot. Generation is something like $-\log(1 - \text{random}()) / \text{bet}$ where $\text{random}()$ returns a random number in $[0, 1)$.