
Optimizing Race Nights!
Thursday nights is game night with my friends and me. We play Forza Horizon 5 and complete the weekly seasonal quests throughout the night. Sometimes we complete it all early and usually we move on to completing accolades, but recently we have run out of decent accolades to do. So, I was tasked with building a random race generator with Python.
Python Code
Introducing the Python program developed to streamline the race selection process, saving time and adding spontaneity to gaming sessions. It’s a very simple script, only thing that took time was gathering the data for each of the lists.
Here’s the basic Python script I wrote:
import random #All Racing Variables location = ['Mexico', 'Rally Adventure', 'Hot Wheels'] carClass = ["X","S2","S1","A","B","C","D"] typeClass = ["Buggies","Classic Muscle","Classic Racers","Classic Rally","Classic Sports Cars","Cult Cars","Drift Cars","Extreme Track Toys","GT Cars","Hot Hatch","Hypercars","Modern Muscle","Modern Rally", "Modern Sports Cars","Offroad","Pick-Ups & 4X4's","Rally Monsters","Rare Classics","Retro Hot Hatch","Retro Muscle","Retro Rally","Retro Saloons","Retro Sports Cars","Retro Supercars","Rods and Customs","Sports Utility Heroes","Super GT","Super Hot Hatch","Super Saloons","Track Toys","Trucks","Unlimited Buggies","Unlimited Offroad","UTV's","Vans and Utility","Vintage Racers"] typeClass_2 = ["Hypercars","Extreme Track Toys"] driveType = ["FWD","RWD","AWD"] festivalRace = ["Mexico","Apex","Wilds","Cross-Country","Street Racing"] festivalRace_2 = ["Horizon Raptors","Grit Reapers","Apex Predators"] festivalRace_3 = ["Speed","Hazard"] #Roll the Dice raceLocation = random.choice(location) carPower = random.choice(carClass) #Race class corrections if carClass == "X": carType = random.choice(typeClass_2) else: carType = random.choice(typeClass) #Race type corrections if raceLocation == "Rally Adventure": race = random.choice(festivalRace_2) elif raceLocation == "Hot Wheels": race = random.choice(festivalRace_3) else: race = random.choice(festivalRace) driveTrain = random.choice(driveType) #Print results print("") print("X"*50) print("The location of the race is:",raceLocation) print("The race shall be:",race) print("The car class is:",carPower) print("The type of car is:",carType) print("With the drive train set to:",driveTrain) print("X"*50) print("")
Specified Parameters
- Location: This decides the scene, whether you race in Mexico, Rally Adventure or Hot Wheels.
- Car Class: This decides the cars power class, “X”, “S2”, “S1”, “A”, “B”, “C”, or “D”.
- Type Class: This decides what kind of vehicle you will race with, from “Buggies” all the way down to “Vintage Racers”
- Drive Type: This decides whether you are to race with “FWD”, “RWD”, or “AWD”.
- Festival Race: This decides what type of race you are to run, I created three different lists for each location.
Necessary Corrections
I needed to create some conditional statements to handle any errors that needed correcting. All that’s left was to print the results to the terminal, so we know what race we have to run.

Conclusion
The program worked very well, saving a lot of time with which race we should try next. As time goes by, I dare say there will be some more conditional statements needed to handle any more corrections I come across but for now this is pretty effective.
That’s All Folks!
You can explore more of our Python guides here: Python Guides