Skip to content

Instantly share code, notes, and snippets.

@kylehamilton
Forked from jknowles/gen_lotto
Created February 20, 2014 23:06
Show Gist options
  • Save kylehamilton/9125197 to your computer and use it in GitHub Desktop.
Save kylehamilton/9125197 to your computer and use it in GitHub Desktop.
# Generate lotto numbers
# Avoid a split pot
# Author: Jared Knowles
# Date: 11/26/2012
# All numbers are equally likely to be selected to win in PowerBall,
# but what fun is winning if we have to share the pot?
# Therefore, we will only select numbers that minimize our
# likelihood of sharing the pot.
gen_lotto<-function(){
white<-seq(1:59)
red<-31:39
probs<-white
# Decrease probabilities for commonly chosen numbers
probs[probs<=31]<-1/(2*59)
probs[probs>=32]<-1/14
# We need 5 white
w<-sample(white,5,prob=probs)
# We need 1 PowerBall
r<-sample(red,1)
# Print results
cat(" White Balls:",w[order(w)],"\n","Powerball:",r)
# Make a good warning
cat("\n Remember, your odds of winning: \n","1 in 195,249,054")
}
gen_lotto()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment