My Goal: Each player has an option to place a bet, and for each player the winning chance of their bet would be calculated and displayed on the web page. So as an example if player 1 bets 5000 credits and the total pot is 15000 credits, player 1 has a 33% chance to win. After this calculation I would like to pick a winner from all the players that placed a bet.
Example game:
Total amount : 15000 credits.
player 1 : 3000 credits -> 20% of winning
player 2 : 1500 credits -> 10% of winning
player 3 : 7500 credits -> 50% of winning
player 4 : 1200 credits -> 8% of winning
Player 5 : 1800 credits -> 12% of winning
How should I approach the way of picking a random winner from all the players? I was thinking of generating one random number and comparing it to the win chance somehow. Any tips?