Created
June 27, 2015 21:01
-
-
Save MrArnoldPalmer/bee4adc78837ebcacf67 to your computer and use it in GitHub Desktop.
Javascript Raffle Randomness
This file contains 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
// 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