Skip to content

Instantly share code, notes, and snippets.

@bkamapantula
Created November 1, 2013 18:38
Show Gist options
  • Save bkamapantula/7269836 to your computer and use it in GitHub Desktop.
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.
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