mercredi 17 février 2016

Increasing chance of a certain number in Math.random within a range

Question Summary

From this SO question I am aware of Math.random(). However, is there a way to increase the chance of a certain number in being chosen?

Situation

  1. I am on a job of creating a raffle system.
  2. I have 10 players.
  3. Each of them has 1 entry for the raffle.This means, initially, each of them has a chance of 1/10 of winning against the others.
  4. They can earn more entries for the raffle.

Problem I can assign a number for each player and do Math.random from 1 to 10, but say player 2 has earned another entry. How do I make number 2 get a better chance of winning?

Notes for possible duplicate claims I am aware of this question closely trying to do the same. However, I am in need of a pure Javascript solution (since this has to be in client side) using Math.random() or other functions you may suggest. Also, this is an entry based random and not a by percent(%) chance.




Aucun commentaire:

Enregistrer un commentaire