makes lottery fair (#652)
previous lottery gave first & last members of the chosen array around half the probability of winning vs. other participants since 0.5-1.5 rounds to 1 but only <0.5 rounds to zero.
This commit is contained in:
parent
f4fbe26bd0
commit
f6e6a7b776
|
@ -2388,7 +2388,7 @@ program
|
||||||
|
|
||||||
console.log('Doing lottery for', numWinnersRemaining);
|
console.log('Doing lottery for', numWinnersRemaining);
|
||||||
while (numWinnersRemaining > 0) {
|
while (numWinnersRemaining > 0) {
|
||||||
const rand = Math.round(Math.random() * (chosen.length - 1));
|
const rand = Math.floor(Math.random() * (chosen.length));
|
||||||
if (chosen[rand].chosen != true && chosen[rand].eligible) {
|
if (chosen[rand].chosen != true && chosen[rand].eligible) {
|
||||||
chosen[rand].chosen = true;
|
chosen[rand].chosen = true;
|
||||||
numWinnersRemaining--;
|
numWinnersRemaining--;
|
||||||
|
|
Loading…
Reference in New Issue