14 Lotto picks

 

Back when I was a C programmer hatchling, I returned from a trip to Las Vegas eager to write my own keno program. Keno is a random-number game, a cross between the lottery and bingo. You pick several numbers in the range from 1 through 80. Payouts depend on how many numbers you choose and guess correctly.

In the process of writing the code, it became apparent that the payouts offered in the casino were nowhere close to the true odds. For example, if you pick 10 numbers and guess correctly, you win $200,000. But the odds of picking 10 out of 10 numbers in a range of 80 numbers are 1:8,911,712. You should win $8,911,712, right? But at least they have killer shrimp cocktail for a dollar. Or they once did.

The process of programming games of chance clues you in to several interesting and useful coding areas, including these:

  • Understanding the odds and probability
  • Calculating the odds
  • Exploring random numbers
  • Simulating drawing lotto balls
  • Running simulations to test the odds

I acknowledge that I’m not a math genius. I understand math, but I got a D in calculus, which was a passing grade, so that’s my limit. I’m not up to par when it comes to the realms of probability and such. After all, it’s the computer that does the math. Your job is to plug in the proper equation and do all those programming things that keep the computer from crashing. The odds on this skill are pretty good.

14.1 A tax for those who are bad at math

14.1.1 Playing the lottery

14.1.2 Understanding the odds

14.1.3 Programming the odds

14.2 Here are your winning numbers

14.2.1 Generating random values

14.2.2 Drawing lotto balls

14.2.3 Avoiding repeated numbers, another approach

14.3 Never tell me the odds

14.3.1 Creating the lotto() function

14.3.2 Matching lottery picks

14.3.3 Testing the odds