I have a map of users and a count of entries/tickets they have purchased for a raffle (or lottery or any other similar event).
The map of users to entries is in the structure as seen below:
// Map the person to the amount of entries they have purchased
$entries = [
'Adam' => 5,
'James' => 3,
'Oliver' => 4,
'Holly' => 8
];
I want to choose a random user but take into consideration their chance based on ticket count. The probability of winning must be:
(User Ticket Amount / Total Ticket Count) * 100 = Probability percentage
For example, from the test array the expected results is Holly will win the raffle 8 times out of 20 times.