Created
November 1, 2013 18:38
-
-
Save bkamapantula/7269836 to your computer and use it in GitHub Desktop.
Generate list of unique pairs (a, b) from N elements ensuring all elements participate in a and b.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, random | |
fout = open('pairs.txt', 'w') | |
# total number of people participating | |
total_people = int(sys.argv[1]) | |
a, b = [], [] | |
for i in xrange(1, total_people+1): | |
a.append(i) | |
while True: | |
r = random.randint(1, total_people) | |
if r not in b and r != i: | |
b.append(r) | |
break | |
for i, j in zip(a, b): | |
fout.write(str(i)+" "+str(j)+"\n") | |
fout.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment