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 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
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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Data Engineering
  3. Data
  4. Random Generator Picks the Indy 500 Winner

Random Generator Picks the Indy 500 Winner

Let's employs a previously covered tool—Random Generator—to pick the winner of the upcoming Indy 500 race, displaying probability and randomness in Java in action.

John Vester user avatar by
John Vester
CORE ·
May. 23, 17 · Tutorial
Like (2)
Save
Tweet
Share
65.28K Views

Join the DZone community and get the full member experience.

Join For Free

with the qualifications completed and the field set for the 101st running of the "greatest spectacle in racing," i thought it would be cool to see which driver would be picked by random generator to get the win for the 2017 indy 500.

image title photo courtesy of bryon j. realey

for those who are not aware of random generator, you can read my series of articles on dzone:

  • building a random generator

  • inside the random generator

  • advanced options for random generator

  • introducing random generator to maven central

or, you can review the source code on gitlab .

setting up the data

since random generator can process a java.util.list object, i created a simple participant object to house each car that qualified for the indy 500.

import lombok.data;

@data
public class participant {
    private integer startposition;
    private integer carnumber;
    private string drivername;
    private string odds;
    private integer rating;
}


if you are not aware of lombok , it is a great utility to keep from having to manually create getters, setters, and a few other boilerplate elements in pojos.

giving odds to the drivers

like any race with established participants, odds are generated for those placing wagers on the competition. while i am not a gambling person, i did decide to use these odds to weigh the participants for the indy 500 race. after all, the drivers in the race certainly have different skill sets and experience — which has proven to be helpful for the first 100 races held in speedway, indiana.

according to sportsbook.ag, the drivers with the best odds are helio castroneves, juan pablo montoya, scott dixon, and tony kanaan with 8:1 odds. the remainder of the field has odds that vary from 9:1 to unlisted. for those unlisted, i gave them odds of 99:1 to win the race.

in order to translate the odds into a "rating" field that random generator can understand, i used the following logic:

100 - the antecedent (or left hand portion of the ratio)

so, those with 8:1 odds were given a rating of 92 (100 - 8).

when enabling the rating functionality in random generator, the rating field will be used to favor drivers with better odds of winning the race. for this experiment, i opted to use a rating level of 2 (rating_level_medium).

random generator in action

with the list<participant> set, i was able to run random generator using the following line of code:

list results = randomgenerator.randomize(participants, 33, 2);

from there, i can use a simple system.out command to paint the order random generator believes will occur:

system.out.println("\nrandom generator results:");
for (int i = 0; i < results.size(); i++) {
    system.out.println((i + 1) + ". " + results.get(i).getdrivername() + " ("
            + results.get(i).getcarnumber() + ") {odds = " + results.get(i).getodds() + "}");
}


my results provided the following finishing order for the 101st running of the indy 500 on may 28th, 2017:

random generator results:
1. tony kanaan (10) {odds = 8/1}
2. josef newgarden (2) {odds = 9/1}
3. will power (12) {odds = 10/1}
4. graham rahal (15) {odds = 25/1}
5. james hinchcliffe (5) {odds = 15/1}
6. jack harvey (50) {odds = 50/1}
7. juan montoya (22) {odds = 8/1}
8. helio castroneves (3) {odds = 8/1}
9. sebastien bourdais (18) {odds = 60/1}
10. alexander rossi (98) {odds = 20/1}
11. ryan hunter-reay (28) {odds = 10/1}
12. marco andretti (27) {odds = 10/1}
13. carlos munoz (14) {odds = 18/1}
14. simon pagenaud (1) {odds = 10/1}
15. ed carpenter (20) {odds = 25/1}
16. takuma sato (26) {odds = 25/1}
17. scott dixon (9) {odds = 8/1}
18. oriol servia (16) {odds = 80/1}
19. charlie kimball (83) {odds = 25/1}
20. fernando alonso (29) {odds = 15/1}
21. jr hildebrand (9) {odds = 20/1}
22. jay howard (77) {odds = 99/1}
23. mikhail aleshin (7) {odds = 80/1}
24. max chilton (8) {odds = 60/1}
25. pippa mann (63) {odds = 99/1}
26. spencer pigot (11) {odds = 99/1}
27. buddy lazier (44) {odds = 99/1}
28. zach veach (40) {odds = 99/1}
29. connor daly (4) {odds = 99/1}
30. gabby chaves (88) {odds = 99/1}
31. sebastian saavedra (17) {odds = 99/1}
32. sage karam (24) {odds = 99/1}
33. ed jones (19) {odds = 99/1}


have a really great day!

Driver (software) Object (computer science) HeliOS Data (computing) DZone House (operating system) Command (computing) Apache Maven

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What Is API-First?
  • 10 Things to Know When Using SHACL With GraphDB
  • Use AWS Controllers for Kubernetes To Deploy a Serverless Data Processing Solution With SQS, Lambda, and DynamoDB
  • Custom Validators in Quarkus

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
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: