Python random sports schedule generator
<p>I found the following</p>

<p><a href="http://stackoverflow.com/questions/5913616/generating-natural-schedule-for-a-sports-league">Generating natural schedule for a sports league</a></p>

<p>That generates the same schedule each time you run it.. If I add a random.shuffle() in there it's still too predictable. </p>

<p>Below is my simple edit from that post with a random in place and I get odd results</p>

<pre><code>import random

def round_robin(units, sets = None):
    """ Generates a schedule of "fair" pairings from a list of units """
    count = len(units)
    sets = sets or (count - 1)
    half = count / 2

    for turn in range(sets):
        left = units[:half]
        right = units[count - half - 1 + 1:][::-1]
        pairings = zip(left, right)
        if turn % 2 == 1:
            pairings = [(y, x) for (x, y) in pairings]
        units.insert(1, units.pop())

        yield pairings


teams = range(5)
random.shuffle(teams)
schedule = list(round_robin(teams, sets = len(teams) * 2 - 2))

for week in schedule:
    for game in week:
        if 0 in game:
            print game
</code></pre>

<p>sometimes it seems teams won't even play each other.. see the results</p>

<pre><code>(0, 4)
(4, 0)
(0, 2)
(0, 4)
(4, 0)
(0, 2)
</code></pre>

<p>My question is.. how can I do a random schedule generator in python or fix what I have already. </p>

<p>Pretty much I need to take 4 teams and come out with 3 weeks of play where they play each other once. Or like 5 teams where there are 5 weeks of play and they all play each other once but one team is left out per week</p>
