Skip to content

Instantly share code, notes, and snippets.

@MrArnoldPalmer
Created June 27, 2015 21:01
Show Gist options
  • Save MrArnoldPalmer/bee4adc78837ebcacf67 to your computer and use it in GitHub Desktop.
Save MrArnoldPalmer/bee4adc78837ebcacf67 to your computer and use it in GitHub Desktop.
Javascript Raffle Randomness
// Basic random number function to select raffle ticket
// Pass # of tickets as parameter
function raffle(tickets) {
return Math.floor((Math.random() * tickets) + 1);
}
var results = {
1: 0,
2: 0,
3: 0,
4: 0,
5: 0,
6: 0,
7: 0,
8: 0,
9: 0,
10: 0
};
// Run i times add results to associative array
for(i=0; i<10000000; i++) {
results[raffle(10)] += 1;
}
// Show results distribution
console.log(results);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment