Trying to create anonymous person-to-person assignments is an interesting algorithmic problem. One trusted source can create the assignments (like my fraternity roast), you can use online tools (like DrawNames for Secret Santa), or you can use this hastily made Go script I made.
When creating a permutation of assignments, we can handle it in multiple ways. Let's say for n people we do the following:
- Assemble a list of Person structs
- Iterate over the list of people
- For each person, randomly select a person from the list
- If the person does not have an assignment, assign them
- Otherwise find another random person
We could encounter the following bad formations for four people:
This is exactly what we're looking for

To resolve this issue we can perform the following algorithm:
- Create a list of nodes for a linked list
- Arbitrarily choose a head
- Connect the head, go to its connection and find a new node
- On the final node connect it to the head
This script can be used by creating a config like example-config.yml and pass it in as a command line argument
go run draw-names.go ./config.yml
Note: if you have 2FA enabled for gmail you should use this instead of your password, https://devanswers.co/create-application-specific-password-gmail/

