Created
August 4, 2011 22:46
-
-
Save egonelbre/1126487 to your computer and use it in GitHub Desktop.
keno loto simulation
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
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