coderholic

Python Bingo Card Generator

Here is a Python script I wrote some time ago. It generates bingo cards based on a number of variables at the top of the file, such as grid size, and number of cards.

#!/usr/bin/env python
import random

gridSize = 5
minNum = 1
maxNum = 50
cards = 40

for h in range(cards):
    card = []
    randRange = range(minNum, maxNum)
    card = random.sample(randRange, gridSize * gridSize)
    for i in range(gridSize):
        string = ""
        for j in range(gridSize):
            string +=  str(card[i + j * gridSize]) + "t"
        print string  

    print "n"

Below if the output when cards is set to 2:

~$ ./bingo.py
11      39      48      19      36
3       12      29      32      31
8       16      5       34      22
14      47      21      26      23
4       13      42      44      28

28      8       15      16      42
10      35      43      38      41
27      17      21      1       4
9       47      11      30      40
49      44      6       45      18
Posted on 09 Apr 2008
If you enjoyed reading this post you might want to follow @coderholic on twitter or browse though the full blog archive.