Using Javascript to Choose Lottery Numbers

August 08, 2015

Winning the Michigan Powerball’s $500 million jackpot is essentially impossible. I’m more likely to get struck by lightning, die from a bee sting, get killed by a vending machine, become an astronaut, or win an academy award.

Yet, for a couple bucks, it’s still entertaining to be a part of such slim odds. My dad brought me two Powerball tickets, the rules, simple: Choose 5 numbers between 1 and 59, and then choose another number between 1 and 35.

For my first ticket, I did what most people do, which is choose numbers that hold some sort of personal significance, i.e. birthdates, my basketball jersey number, etc.

For the second ticket, I wanted to do include something else which is significant for me, which is coding. I decided it’d be cool to use a simple script I’ve had since the early days of learning to code and have it generate these random numbers for me.

function getLotteryNumbers(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min

for (var i = 0; i <= 5; i++) {
  console.log(getLotteryNumbers(1, 35))

After all, my odds of winning (cough losing cough) are just as likely with these randomly generated numbers than anything else I could choose!

Here are my lucky numbers, 2, 18, 19, 22, 43 and 6.

So there we have it. Here’s to javascript, to learning how to code, and to the 1 in 175.2 million odds that I will win some extra pocket change.

Patrick El-Hage

I'm Patrick El-Hage and I live and work in San Francisco. I'm also on Twitter.