Skip to content

Instantly share code, notes, and snippets.

@vicmansep
Forked from jknowles/gen_lotto
Created June 25, 2019 10:19
Show Gist options
  • Select an option

  • Save vicmansep/119de23cfa71844763c0fa0973773b77 to your computer and use it in GitHub Desktop.

Select an option

Save vicmansep/119de23cfa71844763c0fa0973773b77 to your computer and use it in GitHub Desktop.

Revisions

  1. @jknowles jknowles created this gist Nov 27, 2012.
    30 changes: 30 additions & 0 deletions gen_lotto
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    # 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()