[Solved] Ball Lottery Algorithm [closed]


You don’t need to store ranges, only probabilities, or in your case the number of balls they have.

Player 1 has 60 balls. You can store that directly as an int 60. Player 2 has 20, so store 20. And so on.

Then count the total number of balls (once, or hardcode it if it known statically), and draw a random number between 0 (included) and the number of balls (excluded).

Loop over the players, add up their number of balls as you loop. Return the first player for which the accumulated number of balls is higher than your random number.

1

solved Ball Lottery Algorithm [closed]