Skip to content

Instantly share code, notes, and snippets.

@avdg
Last active October 12, 2017 20:37
Show Gist options
  • Save avdg/6a6c5cb47376ec89e5d450f024ef3a5d to your computer and use it in GitHub Desktop.
Save avdg/6a6c5cb47376ec89e5d450f024ef3a5d to your computer and use it in GitHub Desktop.
Lotery
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