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.
Join the DZone community and get the full member experience.
Join For Freewith 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.
photo courtesy of
bryon j. realey
for those who are not aware of random generator, you can read my series of articles on dzone:
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!
Opinions expressed by DZone contributors are their own.
Comments