Skip to content

Instantly share code, notes, and snippets.

@avdg
Last active Oct 12, 2017
Embed
What would you like to do?
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