# Chance of adjacent lockers with the same combination

One weird thing that happened to me in high school was that the combination lock on my locker had the exact same combination as the locker next to it. It always struck me that the odds were crazy on this, but I never calculated it.

The lock was a masterlock, the kind where you have 40 options for the first number, then 39 for the second (can't use the first number again), then 39 for the 3rd number (you can use the first number again for it).

• 1/59,280 chance that two locks have the same combination. (40 * 39 * 39)
• 1/29,640 chance that any specific combination is next to mine (w/2 lockers next to mine).

That gives a 1 in (59,280 * 29,640) chance that a specific combination is next to mine? Or a 1/1,757,059,200 chance.

This seems way too high, and there's probably something I'm missing here. Any thoughts on this calculation, or what it should be?

• Your locker's combination is now the target. You are hoping either the one on your left matches it OR the one to your right matches it. It seems to me is a simple '+' instead of '*'. – Mick Dec 21 '13 at 5:00
• Is your anecdote really true!? – Sammy Black Dec 21 '13 at 5:00
• Mick's right. The odds are therefore about 1 in 30,000. That's small, but not insane. Then again, it suggests that your estimate of the number of combinations might be wrong. I seem to (vaguely) recall that the first number on a Master combination lock was always congruent to 1 mod 4 (or something like that), and a similar rule held for the second and third, i.e., there are about 64 times FEWER possibilities than you might imagine. If so, then yours was about a 1-in-500 chance, which is the sort of thing that does really happen. – John Hughes Dec 21 '13 at 5:05
• Sammy: It is true! I confronted the guy at the end of the semester about it, and asked to buy his lock. He sold it to me and said the combination, asking if I needed to write it down. I told him this anecdote about how I accidentally opened his locker once and thought someone had stolen everything of mine and replaced it. I think he was too shocked that someone had been in his locker to be sufficiently shocked by the chances of it actually happening. – AdamFortuna Dec 23 '13 at 4:31

## 2 Answers

As you correctly calculated, there is a $1$ in $40 \times 39 \times 39 = 60\,840$ of another lock having the same permutation (they're not combination locks, as order does matter). So what is the probability that either of your neighbors has the same permutation?

It's easier to calculate the complementary event: both of your neighbors have different permutations. The probability is \begin{align} P(\text{ diff. on left } \cap \text{ diff. on right }) &= P(\text{ diff. on left }) \times P(\text{ diff. on right }) \\ &= P(\text{ diff })^2 \\ &= \left( \frac{60839}{60840} \right)^2 \end{align}

Therefore, \begin{align} P(\text{ either neighbor same }) &= 1 - \left( \frac{60839}{60840} \right)^2 \\ &= \frac{121\,679}{3\,701\,505\,600} \\ &\approx 0.0000329, \end{align} or roughly $1$ in $30\,420$.

• Although this is a splendid mathematical solution, master locks do not have $60840$ combinations. See here; in fact they have only $1000$. – vadim123 Dec 21 '13 at 5:21
• @vadim123, while the mod 4 conditions relating numbers in a Master Lock combination imply there are only 100 possible combinations with a particular (say) fist number, that first number can be any of 40 values, so the number of possible combinations is 4000, not 1000. – KCd Jul 4 '15 at 16:47
• @KCd, read the link I included and you will find a mechanical way to find the last number, reducing the total combinations to just 100. – vadim123 Jul 4 '15 at 17:15
• @vadim123, I agree that once you find a number in one of the positions (the last position in practice) there are only 100 possibilities for the overall combination, but the number you find in that position could be any of 0,1,...,39, so the overall number of combinations available in MasterLock space is $40\cdot 100 = 4000$. – KCd Jul 4 '15 at 17:23

It is worth examining the following related problem which has a very interesting non-intuitive answer:

What is the probability that two people at a school of $1000$ have the same locker combination?

Since there are $59280$ different possible locker combinations, one might naively guess that for $1000$ students, the probability that two have the same locker combination is about $1$ in $59$. However, this heuristic is completely wrong, and the probability is much higher than $1$ in $59$.

Lets calculate the probability that all $1000$ students have different locker combinations. This equals $$\frac{59280}{59280}\cdot\frac{59279}{59280}\cdot \frac{59278}{59280}\cdots\frac{58281}{59280}=0.00020885\dots,$$ and so the probability that two students have the same locker combination is $0.99979$. In other words, in a school $1000$ students, there is a $99.979$% chance that two will have the same locker combination.

• (+1) for the generalization to match between any lockers, which is a variation of the birthday problem. – Frenzy Li Dec 21 '13 at 5:25
• Since the number of actual Master Lock combinations is only 4000 (due to the mod 4 constraints $c\equiv a \bmod 4$ and $b \equiv a+2 \bmod 4$ on a Master Lock combination $(a,b,c)$ -- see the link in the comment by vadim123), the probability is even higher than what you wrote. Using 4000 in place of 60840 (you write 59280, which is an error by the OP since that is $40 \cdot 39 \cdot 38$) and taking a product for the complementary event of no shared combination among 1000 people, the probability of at least one shared combination among 1000 people is around $1−e^{−136}$. – KCd Jul 4 '15 at 17:28
• @KCd: Thanks for pointing this out! I didn't realize that Master Locks work that way. – Eric Naslund Jul 5 '15 at 22:20