Im very sorry if the title is a little bit misleading!
So basically i have this:
Example 1:
var array = [30,30,30]
or Example 2:
var array = [10,50,20]
I need to pick a winner from these numbers with percentages. Example: 50 wins 5 times more often than 10.
I have solution for that but it doesnt really work and is inaccurate. Update: This solution doesnt have anything to do with what i really want.
var array = [10,50,20];
var totalValue = 80;
array.sort();
array.reverse();
var lowestNumber = array.slice(-1)[0];
total += lowestNumber;
var random = Math.floor((Math.random() * total) + lowestNumber );
array.some(function(entry) {
if (entry < random) {
console.log('winner', entry)
return true;
}
})
This script is working on the second example, but 20 has a way to higher chance to win and the first example of course doesnt work at all.
Im happy for every answer / comment!