Skip to content

Instantly share code, notes, and snippets.

@egonelbre
Created August 4, 2011 22:46
Show Gist options
  • Save egonelbre/1126487 to your computer and use it in GitHub Desktop.
Save egonelbre/1126487 to your computer and use it in GitHub Desktop.
keno loto simulation
function PickNumbers(count, total){
var i, set = [],
result = [];
for(i=total; i--;)
set.push(i);
for(i=count; i--;){
var picked = (Math.random() * set.length) | 0;
result.push(set[picked]);
set.splice(picked,1);
}
return result.sort();
};
function Matches(mine, set){
var matches = 0;
for(var i = mine.length; i--;)
for(var j = set.length; j--;)
if( mine[i] == set[j] )
matches += 1;
return matches
}
function Simulate(bank, pay, turns){
for(var i=turns; i--;){
bank -= pay;
mine = [0,1];
keno = PickNumbers(20,64);
if( Matches(mine, keno) >= 2)
bank += pay*5;
console.log(bank);
if(bank < 0)
console.log('broke');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment