Okay, so I wanted to build something fun in my spare time, and I thought, why not create an MLB player generator? It’s something I’ve been thinking about for a while, and I finally decided to just go for it. I started by sketching out the basic idea on a piece of paper. I wanted the generator to create players with different positions, batting averages, home runs, and all that good stuff.
First things first, I needed a way to store all the player data. So I whipped up a simple list in Python. I figured I could use dictionaries to represent each player, with keys for their name, position, and stats. It was pretty straightforward to set up.

Here’s how I started:
- I created an empty list called
players
. - Then, I made a few sample player dictionaries, like:
player1 = {'name': 'Babe Ruth', 'position': 'Outfielder', 'batting_average': .342, 'home_runs': 714}
And I added them to the players
list. Easy peasy.
Next, I needed a way to generate new players. I thought it would be cool to randomize the stats a bit, so I used Python’s random
module. I wrote a function called generate_player
that would create a new player dictionary with random values for each stat. It was a bit tricky to get the ranges right, but after some trial and error, I got it working.
Generating Players
This part was actually pretty fun. I played around with the random ranges to make sure the generated players were somewhat realistic. I didn’t want any players with a batting average of 1.000 or 2,000 home runs! After some tweaking, I was pretty happy with the results.
Here’s the gist of the generate_player
function:
- Generate a random name (I just made up some names for now).
- Choose a random position from a list of possible positions.
- Generate random stats within reasonable ranges.
- Pack it all into a dictionary and return it.
Finally, I wanted to be able to display the generated players in a nice way. I just used some simple print statements to output the player’s name, position, and stats. Nothing fancy, but it gets the job done.

I ran the generator a few times, and it was actually pretty cool to see the different players it created. Some were superstars, some were average, and some were, well, not so great. Just like in real life!
So, that’s how I built my little MLB player generator. It was a fun project, and I learned a lot along the way. I’m thinking about adding more features in the future, like maybe generating entire teams or simulating games. We’ll see! It’s not perfect, but it’s mine, and I’m pretty proud of it. Maybe one day I can make it good enough to sell to one of those big video game companies. But it’s just a little side project for now. Hope you found this interesting!