I'm developing a node.js app where a winner has to be randomly selected based on it's win probability in the range of [0, 100] %
My code is as follows:
var activeGame = {
id: 12324,
type: 1,
active: true,
players: [{
id: 5032,
name: "Username",
foo: true,
winProbability: 56.32 //%
}, {
id: 98243,
name: "Username",
foo: true,
winProbability: 22.68 //%
}, {
id: 10943,
name: "Username",
foo: false,
winProbability: 21.00 //%
}],
};
I've found other algorithms that weren't very clear and didn't work with probabilities adding up to 100%.
I'm looking for a way to create a function selectRandomWinner()
to return the index of the winning player but I'm stuck and all and any help would be greatly appreciated. Thanks!
Aucun commentaire:
Enregistrer un commentaire