DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Migrate, Modernize and Build Java Web Apps on Azure: This live workshop will cover methods to enhance Java application development workflow.

Modern Digital Website Security: Prepare to face any form of malicious web activity and enable your sites to optimally serve your customers.

E-Commerce Development Essentials: Considering starting or working on an e-commerce business? Learn how to create a backend that scales.

Related

  • Event-Driven Order Processing Program
  • Keep Your Application Secrets Secret
  • GitOps: Flux vs Argo CD
  • GitHub Security 101: Best Practices for Securing Your Repository

Trending

  • CodeCraft: Agile Strategies for Crafting Exemplary Software
  • Evolution of Software Architecture: From Monoliths to Microservices and Beyond
  • Testing Swing Application
  • 5 Steps To Tame Unplanned Work
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Using Random Generator to Hit the Powerball Jackpot

Using Random Generator to Hit the Powerball Jackpot

As we continue to explore weights and randomness, see how an open source library tackles winning the biggest prize of them all: the lottery.

John Vester user avatar by
John Vester
DZone Core CORE ·
Mar. 07, 17 · Tutorial
Like (1)
Save
Tweet
Share
126.5K Views

Join the DZone community and get the full member experience.

Join For Free

Recently, I completed a series on an open source library I created called Random Generator. Upon completion of the series, I wrote another article focused on using Random Generator to correctly pick the teams for the NCAA Men's Basketball tournament, using results and information from the 2015-2016 season. If you want to read my series on Random Generator, below are links to each article in the series:

  • Building a Random Generator

  • Inside the Random Generator

  • Advanced Options for Random Generator

  • Introducing Random Generator to Maven Central

As part of my daily commute, I drive past one of those lottery signs that provides an update for the latest estimated payouts for various lottery games available in my area. The biggest lottery in the Midwest is the Powerball. I remember there being a couple really large payouts last year, so I wondered if Random Generator could pick the winner number for one of those drawings.

How Powerball Works

The Powerball drawing randomly picks five numbers out of a list of 69 choices. Then a single Powerball is picked, which ranges from 1 to 26. If you are lucky enough to pick all six numbers, you win the jackpot. The odds of winning the jackpot are 1 in 292,201,388.

According to an article published by CNN Money, you have better odds for the following items to happen:

  • Give birth to quadruplets (1 in 729,000)

  • Be killed by an asteroid strike (1 in 700,000)

  • Be killed by a lightning strike (1 in 164,968)

NBC News provided some less morbid comparisons in this article:

  • Being drafted into the NBA after college (1 in 6,864,000)

  • Dating Actor Brad Pitt (1 in 1,505,000)

  • Becoming the US president (1 in 10,000,000)

  • Making a hole in one on a par 3 hole as an amateur golfer (1 in 12,500)

The Powerball Jackpot

Looking at the history of the Powerball drawings, I decided to focus on the November 27, 2016 Powerball drawing, which had escalated to a winning prize of $420.9 million (US). The winning numbers are listed below:

17 19 21 37 44 and the Powerball was 16

That drawing had only a single winner, which had an estimated cash value of $254.6 million (US) and the winning ticket was purchased in the state of Tennessee.

Random Generator

Since Random Generator was designed to randomize elements of a java.util.List and can be configured to return a subset of the list, I decided to see if Random Generator could correctly pick the winning numbers from the November 27th drawing. First, I created two simple methods to build a list of java.lang.Integer objects. One for the main range of numbers:

private static ArrayList<Integer> getMainNumbers() {
    ArrayList<Integer> returnList = new ArrayList<Integer>();
    returnList.add(new Integer("1"));
    returnList.add(new Integer("2"));
    ...
    returnList.add(new Integer("68"));
    returnList.add(new Integer("69"));
    return returnList;
}


One for the Powerball range of numbers:

private static ArrayList<Integer> getPowerballNumbers() {
    ArrayList<Integer> returnList = new ArrayList<Integer>();
    returnList.add(new Integer("1"));
    returnList.add(new Integer("2"));
    ...
    returnList.add(new Integer("25"));
    returnList.add(new Integer("26"));
    return returnList;
}


With these methods in place, it was easy to use Random Generator to provide a list of Powerball picks:

RandomGenerator randomGenerator = new RandomGenerator();
List<Integer> myPicks = randomGenerator.randomize(getMainNumbers(), new Integer("5"));
List<Integer> myPowerball = randomGenerator.randomize(getPowerballNumbers(), new Integer("1"));


From the Powerball odds page, I realize that picking one set of Powerball picks has very low odds at matching the winning numbers, so I updated the code in a for loop so that I could repeat the process multiple times:

for (int i = 0; i < loopCount; i++) {
    List<Integer> myPicks = randomGenerator.randomize(getMainNumbers(), new Integer("5"));
    List<Integer> myPowerball = randomGenerator.randomize(getPowerballNumbers(), new Integer("1"));

    // processing logic occurs here ...
}


I added processing logic to keep track of the number of times each number, which was part of the winning set, was found. I then kept track of the number of times matches that provide a payout (e.g. two numbers and the Powerball) were encountered as well.

With the code in place, I set loopCount to 10 million iterations. While Random Generator did not correctly pick all the numbers correctly, it did yield the following results:

Found winning number 17 = 723,271 time(s)
Found winning number 19 = 723,596 time(s)
Found winning number 21 = 724,907 time(s)
Found winning number 37 = 724,610 time(s)
Found winning number 44 = 723,373 time(s)
Found Powerball (16) = 384,708 time(s)

Instances with 2 correct numbers = 370,272
Instances with 3 correct numbers = 18,013
Instances with 4 correct numbers = 289
Instances with 5 correct numbers = 2
Instances where all numbers were found, except the Powerball = 2
Tickets with zero matches = 6,526,799

Based upon the current Powerball payouts, the following winnings would be applied, based upon 10 million iterations:

Powerball (only) Match = $1,042,468.00
1 + Powerball Match = $436,400.00
2 + Powerball Match = $100,037.00
3 Matches (no Powerball) = $126,091.00
3 + Powerball Match = $69,100.00
4 Matches (no Powerball) = $28,900.00
4 + Powerball Match = $450,000.00
5 Matches (no Powerball) = $2,000,000.00
Grand Prize = $0.00
Total Prize Money = $4,252,996.00
Ticket Costs - Total Prizes = ($15,747,004.00)

In the end, an investment of $20 million in Powerball tickets led to a return of only $4.3 million, or a Return on Investment (ROI) of -79%. Of course, hitting the jackpot one time, is all that it would have taken to make the investment worthwhile.

Updates to lotterypick

The code I used for the test above has been added to my GitLab account and can be found at the following URL:

https://gitlab.com/johnjvester/lotterypick

Buying 10,000 million quick picks (random picks) does not guarantee duplicates from being purchase. However, I have been working on updates to employ the use of a java.util.HashSet to make sure all processed picks are unique. In introducing this logic, I have been dealing with increased memory usage and performance when processing over 40 million unique picks.

You are welcome to download or fork this repository. Be warned, the code was for exploratory purposes and is far from the best code I have ever written.

Have a really great day!

Open source Processing Memory (storage engine) Subset LEd Repository (version control) neural network

Opinions expressed by DZone contributors are their own.

Related

  • Event-Driven Order Processing Program
  • Keep Your Application Secrets Secret
  • GitOps: Flux vs Argo CD
  • GitHub Security 101: Best Practices for Securing Your Repository

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: