The Problem
This year we wanted to organise an inclusive Secret Santa gift exchange and not everyone is quite tech-savvy. We tried putting small pieces of paper with our names in a bag and then shuffling them around. But we wanted to avoid exchanging gifts between partners... so that didn’t work. We kept drawing our own partner, and if by some luck we didn’t, someone would draw their own name! After about 30 tries we gave up and rescheduled the draw to a few days later until I sort something out.
How I Approached It
The first decision was easy: no server. Client-side only. I didn’t want to run a database or store anyone’s names anywhere; it’s completely unnecessary for something this simple, and honestly I had already planned of putting it online, so that would have created a privacy concern that I didn’t want to deal with.
The interesting part is the draw algorithm itself. What you need is a derangement; a permutation where no element appears in its original position, meaning nobody draws themselves. Add exclusion pairs on top of that (person A cannot draw person B), and it becomes a constrained derangement problem.
For small groups, a simple approach works well: shuffle the list randomly and check whether all constraints are satisfied. If not, shuffle again and retry. In practice, this converges in a handful of attempts unless the constraints are so tight that no valid solution exists. If that happens, the app tells you clearly rather than looping forever.
The results are shown directly in the browser, one person at a time, so people can check their own draw privately on their phone without anyone else seeing. No emails, no links, no account needed.
The most surprising thing was that people actually used it. I shared it in a couple of group chats expecting it to be ignored, but actually received some good immediate feedback. It does make life easy to draw names for a gift exchange when all participants are in the same room, especially if they are not all tech-savvy, not all have an email address, and everyone wants to participate without knowing who has who.
Sometimes the most useful things are truly the simplest ones.
Try it out here: Secret Draw tool.