An app to organize your Secret Santa

An app to organize your Secret Santa

snow flakes falling

I made a thing!

I designed an app to help people organize Secret Santa gift exchanges from afar. You enter in the participants and their email addresses, and the app randomly pairs people into giver and recipient. It emails all the participants to let them know who they are the Secret Santa for.

I’m envisioning people using it to organize gift exchanges at their workplace, and amongst friends or family (especially over long distance).

By working over email, the Secret Santa pairs can be kept truly secret. But there is also an option to email out a master copy, just in case.

None of the email addresses you enter are kept after you’re done using the app. In fact, there’s a handy button to clear your data at any point.

I made the app to play around with PHP sessions. I’ve always used $_POST to handle passing data from client to server. But in some of my apps, it gets a little silly. Each volley required repopulating arrays unnecessarily. I gave up on sessions quickly before because I was having trouble getting them working on localhost. But now, embarrassingly, I think the problem was simply that I was trying to assign a $_Session variable rather than $_SESSION.

I won’t even tell you how much time I spent playing around with my PHPAdmin settings before I figured that one out. *facepalm*

Surprises in front end UI

I first debuted my little app to friends over facebook. I was shocked to find that they all assumed the app would enter them into some global Secret Santa amongst everyone who used it.

I went back to look at the user interface and realized that in my quest to be minimalistic, it really did look like that. There was just an option to add your name, email, and click “add”.

If they had played with it further, they would see more options appear as they added more names (at least 3 to generate the Secret Santa). But who would risk committing to some rando global gift exchange to figure that out??

I’ve added more text to explain how it works. But I don’t like that solution. I’ll probably tinker with it more to make the purpose of the app clear without a bunch of text.

If you have ideas towards this end, let me know in the comments!

Thinking ahead on the back end

There is some functionality baked in that users don’t yet have access to.

Sometimes it can be useful to make a Secret Santa where certain people can’t draw each other. Maybe it’s to avoid couples getting each other’s name. Maybe it’s office politics. So to achieve this, each participant is associated with a set of probabilities that they will draw every other name.

The algorithm uses the probability set to define a line, and wherever a random number falls on this line determines which name gets paired. (The unique identifier for each name is the email address $email, which is assigned a probability $prob.)

function checkWithSet(array $set, $length=10000) {
   $left = 0;
   foreach($set as $email=>$prob) {
      $set[$email] = $left + $prob*$length;
      $left = $set[$email];
   $test = mt_rand(1, $length);
   $left = 1;
   foreach($set as $email=>$right) {
      if($test>=$left && $test<=$right) {
         return $email;
      $left = $right;
   return null;// debug, no event realized

In principle, making the line longer (increasing $length) would make the probabilities more accurate. However, that only takes you so far since the random number generator is really only pseudorandom. At any rate, it works well enough for the purpose!

So the algorithm goes through the list of participants and uses checkWithSet() to have each “draw a name”. After a name is drawn, the drawn name is removed from the other participants’ sets. (Much like drawing a name from a hat removes that name from the hat for future draws.) Before each participant draws a name, their set of probabilities is re-normalized to account for the options that have been removed.

It could happen that a participant has no options left to draw when their “turn” comes. The algorithm is set to make multiple attempts at running the entire draw sequence in case that happens, but nothing more than that has been put in place to avoid such a scenario. I can see it being a bigger problem if the probability of drawing each name is very tightly constrained.

I still need to work out a front end interface to give users optional access to the matrix of probability pairs, in a way that makes intuitive sense.

Do you have a feature idea for the Secret Santa app? Did you give it a try? Let me know in the comments!

Leave a Reply

Your email address will not be published. Required fields are marked *