Last active
October 12, 2017 20:37
-
-
Save avdg/6a6c5cb47376ec89e5d450f024ef3a5d to your computer and use it in GitHub Desktop.
Lotery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var probabilities = [500, 200, 50, 5]; | |
var iterations = 2000; | |
var results = []; | |
next: | |
for (let i = 0; i < iterations; i++) { | |
let probability = Math.floor(Math.random() * 1000); | |
let j = 0; | |
while (j < probabilities.length && probabilities[j] >= probability) { | |
j++; | |
if (j >= probabilities.length) { | |
continue next; | |
} | |
} | |
if (results[j]) { | |
results[j]++; | |
} else { | |
results[j] = 1; | |
} | |
} | |
console.log(results); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment