3 ms·
The real tricky part is making an algorithm that gives a uniformly random Secret Santa. In fact even generating a random permutation is quite tricky. Usually t
by contravariant 11y ago
The real tricky part is making an algorithm that gives a uniformly random Secret Santa. In fact even generating a random permutation is quite tricky.
Usually the easiest is to just use Fisher-Yates to get a random permutation and reject it if it doesn't fit the criteria (people shouldn't pick themselves etc.). For nearly all practical problem sizes this should be fast enough.
Trying to reject permutation half way and fixing it has a tendency to cause subtle biases.