MegaMillions Random Number Generator

Michael J. Pfammatter
2015-01-25

Purpose

Deciding what numbers to pick when playing the lottery can be daunting, particularly when there are millions of dollars on the line. We are here help you out with your MegaMillions game by providing you with a smarter 'Random Number Generator' to help put some money in your pocket. We are going to play with the MegaMillions game.

Winning number history

To be smarter about selecting numbers, we need to look at the history. Since the rules of the game changed after 2013-10-20, we need to make sure we only use numbers from after that date.

library(XML); library(reshape2);library(dplyr)
url <- 'http://www.wilottery.com/lottogames/megamillionshistoryOD.aspx'
doc <- htmlParse(url)
tableNodes <- getNodeSet(doc, "//table")
win <- readHTMLTable(tableNodes[[1]], 
  header = c("DrawDate", "n1", "n2", "n3", "n4", "n5", "MegaBall", "Megaplier"),
  colClasses = c("character", "integer", "integer", "integer",
               "integer", "integer", "integer", "integer"))
win$DrawDate <- as.Date(substr(as.character(win$DrawDate), 6, 18), "%b %d, %Y")
win <- filter(win, DrawDate > "2013-10-20")

Winning number frequency

Then we can take a look at with what frequency each number has been chosen so far plot of chunk unnamed-chunk-2