Created
December 9, 2011 10:22
-
-
Save nskvortsov/1451007 to your computer and use it in GitHub Desktop.
Lottery
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 try_to_win() { | |
// assume random is in [0,1] | |
int i = round(random() * 100) | |
if (i == 100) { | |
return UBELIEVABLE_JACKPOT // May never happen | |
} else if (i > 95) { | |
return BIGGEST_PRIZE // about once in 20 rolls | |
} else if (i > 75) { | |
return MIDDLE_PRIZE // about once in 4 rolls | |
} else if (i > 30) { | |
return TINY_PRIZE // about 2 out of 3 rolls | |
} else { | |
return DAMN_ITS_EMPTY; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment