Skip to content

Instantly share code, notes, and snippets.

@tecteun
Forked from thepauljones/timtamlottery.js
Last active March 4, 2016 09:37
Show Gist options
  • Save tecteun/0716e8f6350b59aa1067 to your computer and use it in GitHub Desktop.
Save tecteun/0716e8f6350b59aa1067 to your computer and use it in GitHub Desktop.
Open sourced code to determine who in the team gets the overige tim tams after everyone has had one
var totalTimTamsinPack = 8; //For the Hellema brand
var people = ["fardau", "wilfred", "jeroen", "teun", "arjan", "erik", "paul"];
var usecrypto = true;
var timtamsleftAfterEveryoneGetsOne = totalTimTamsinPack - people.length;
var array = new Uint32Array(1);
while(timtamsleftAfterEveryoneGetsOne-- > 0){
var winer = null;
if(usecrypto){
window.crypto.getRandomValues(array);
winer = people[Math.floor(array[0]/ (0xFFFFFFFF / people.length))];
}else{
winer = people[Math.floor(Math.random()*people.length)]
}
alert("The " + (timtamsleftAfterEveryoneGetsOne + 1 )+ "nd last tim tam goes to " + winer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment