Projects

Bingo Generator

Python

A script to generate random, non-repeating bingo cards.

A sample bingo card.

During the pandemic, my wife and I had to plan a digital baby shower. Our family wanted to include games people could play during a Zoom call, and one option that came to Monday was one of those someone said something, mark it down bingo games. Writing up cards by hand felt excessive, and I offered to write a script to generate the cards for us.

At first glance the problem is simple: just make a random list of words with FREE in the center space. But randomness introduces the probability of multiple cards having the same win states, especially if there are not enough values to choose from and a lot of cards being distributed. There’s 12 possible win states on each card, so 20 cards with 12 possible win states requires checks back of napkin a lot of freaking text values.

I didn’t have enough time to find an optimal solution, so I tried a point system - if a value appeared in the same spot as another card, the latest card gained a score of 5 points. Having the duplicate value at all increased it by 1. Then I could set a threshold and have some level of certainty that there wouldn’t be too much overlap.

Unfortunately, that wasn’t the case. As mentioned above, a card has 12 win states, and just because the value isn’t in the exact same spot, that doesn’t mean it can’t be part of the exact same win state.

If I were to revisit or correct the code, I don’t think checking for win states after randomly generating the card is enough - I would look for a way to generate win sets and build a card using those instead. That’s a much harder problem to solve, but it would make for a much more effective bingo generator.

This was also my first attempt at creating a git repo that looked like a real developer’s git repo - minus the missing unit tests. I enjoyed throwing this one together a lot, as scripting and product design are two of my favorite things to do at work, and I love watching how requirements and code meet in the middle to show the strengths and weaknesses of each.