Random Pairing

John Hunter jdhunter at ace.bsd.uchicago.edu
Tue Jul 6 13:45:39 EDT 2004


>>>>> "Jared" == Jared  <knowlj at hotmail.com> writes:

    Jared> For a tournament I'm making a random pairing generator.  I
    Jared> haven't quite figured out how to randomly pair yet though.
    Jared> Here's what I have so far:

Assuming you have 100 players, you can shuffle the index vector and
use zip to create a sequence of pairs

>>> from random import shuffle
>>> ind = range(100)
>>> shuffle(ind)
>>> pairs = zip(ind[::2], ind[1::2])
>>> print pairs
[(3, 51), (88, 73), (41, 62), (14, 38), (90, 2), (58, 26), (72, 19), (77, 89), (0, 30), (74, 49), (95, 67), (92, 60), (86, 76), (27, 25), (65, 22), (96, 23), (66, 43), (57, 12), (59, 54), (70, 55), (82, 61), (64, 40), (16, 85), (31, 48), (78, 52), (39, 53), (17, 13), (99, 5), (45, 71), (4, 9), (97, 83), (8, 7), (15, 56), (42, 84), (94, 91), (75, 29), (33, 80), (68, 28), (21, 1), (10, 37), (18, 93), (98, 32), (50, 36), (44, 11), (34, 69), (24, 79), (6, 46), (20, 35), (63, 87), (81, 47)]
>>>




More information about the Python-list mailing list