I am writing a pairing program for round-robin/double round-robin/swiss tournaments. I am looking for the rules to follow while generating the pairings. There seem to be no rules in the FIDE handbook. The only rule I know is that in tournaments like the FIDE Candidates players of the same federation are paired together as early as possible. Do there exist any other restrictions, or do I just pair the players randomly such that each player plays every other player in the tournament?