Well, imagine I'm creating a Pokemon game in JavaScript. I have such an object ...
pokemon = { "pikachu": {hp: 100, probability: 0.1}, "squirtle": {hp: 90, probability: 0.2} };
I basically need a function to select PokΓ©mon in an object at random, but also based on probability. Thus, in this case, the functions are more likely to select "squirtle", since the probability is higher than "pikachu".
Danny source share