Skip to content

Instantly share code, notes, and snippets.

@nskvortsov
Created December 9, 2011 10:22
Show Gist options
  • Save nskvortsov/1451007 to your computer and use it in GitHub Desktop.
Save nskvortsov/1451007 to your computer and use it in GitHub Desktop.
Lottery
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