This problem is a beautiful and elegant probability based on an elementary problem on how to effectively choose the key to a lock. This gives a simulation environment to problem 6 of ISI MStat 2017 PSB.
Suppose you have a 4-digit combination lock, but you have forgotten the correct combination. Consider the following three strategies to find the correct one:
(i) Try the combinations consecutively from 0000 to 9999.
(ii) Try combinations using simple random sampling with replacement from the set of all possible combinations.
(iii) Try combinations using simple random sampling without replacement from the set of all possible combinations.
Assume that the true combination was chosen uniformly at random from all possible combinations. Determine the expected number of attempts needed to find the correct combination in all three cases.
This problem really intrigues me, which gives me the excitement to solve and solve it.
\(U\) ~ Discrete Uniform \(({0, 1, 2, ..., 9999})\)
Suppose, observe that if you select the keys consecutively, then for the true key \(U\), you need \(U\) attempts. (*)
\(N\) denotes the number of attempts required = \(U + 1\) due to (*)
\( E(N) = E(U) = \frac{9999}{2}\).
This is something no one does, but let's calculate this and see why we don't do this and why we need to remember the keys that don't work like SRSWOR, which is the next case.
\(U\) ~ Discrete Uniform \(({0, 1, 2, ..., 9999})\)
\(N\) denotes the number of attempts required. \( E_U(E(N|U)) = E(N)\)
Let's say, we have observed \(U\), which is fixed and we will calculate \(E(N|U)\).
Observe that \(N|U\) ~ Geom(\frac{1}{10000}\), since, there are unlimited trials and success occurs if you pick up the right key \(U\), which has a probability of \(\frac{1}{10000}\).
Therefore, \(E(N|U) = 10000\). Hence, \( E(N) = E_U(E(N|U)) = 10000\)
#Simple Random Sampling with Replacement
NUM = 0
size = 1000 # we have taken 1000 for easier calculation
key = sample(size,1)
number = NULL
random = sample(size,1)
N = 1
for (k in 1:1000) {
number = NULL
for (j in 1:100)
{
while (random != key)
{
random = sample(size,1)
N = N + 1
}
number = c(number,N)
random = sample(size,1)
N = 1
}
NUM = c(NUM,mean(number))
}
mean(NUM)
980.899
hist(NUM)
#Note Replace = TRUE will not work, since, this is an open-ended program
Hence, this is validated by our simulation.
This is the sort of key selection, we usually do. Let's investigate it.
\(U\) ~ Discrete Uniform \(({0, 1, 2, ..., 9999})\)
\(N\) denotes the number of attempts required. \( E_U(E(N|U)) = E(N)\)
Let's say, we have observed \(U\), which is fixed and we will calculate \(E(N|U)\).
\( p_i = P ((N|U) = i) = \frac{9999}{10000}.\frac{9998}{9999}.\frac{9997}{9998}...\frac{10001-i}{10002-i}.\frac{1}{10001-i} = \frac{1}{10000}\)
\(E(N|U) = \sum_{i = 0}^{9999} ip_i = \sum_{i = 0}^{9999} i \cdot \frac{1}{10000} = \frac{9999}{2} \). Hence, \( E(N) = E_U(E(N|U)) = \frac{9999}{2}\).
#Simple Random Sampling without Replacement
average = NULL
number = NULL
size = 10000
key = sample(size,1)
for (j in 1:1000)
{
for (i in 1:100)
{
option = sample(size,size, replace = FALSE)
v = which(option == key)
number = c(number,v)
}
average = c(average,mean(number))
}
mean(average)
4996.567
hist(average, freq = FALSE)
Stay tuned!
Stay Blessed!

Publishing original scientific research in a peer-reviewed journal is an achievement many scholars work toward for years. Achieving this feat early in one's academic journey requires exceptional intellectual rigor, creativity, and persistence. Aaditya Punatar and Muskan Sadana have reached this remarkable milestone, successfully publishing their collaborative research paper in the prestigious Journal of Emerging Investigators […]

Her project on quantum-accelerated Steiner trees for 15-minute cities earned a place among the finalists at the world's largest pre-college STEM competition. Prishaa Shrimali of Marymount School of New York, was selected as a Grand Finalist at the 2026 Regeneron International Science and Engineering Fair (ISEF) in Phoenix, Arizona. Her project was Optimizing Urban Accessibility: […]

In 2026, the following Cheenta students have been successful for Indian Statistical Institute's M.Stat Entrance. They ranked within the first 50 in the entire country in these entrances. I.S.I. M.Stat Entrance

In 2026, the following Cheenta students have been successful for Indian Statistical Institute's B.Stat Entrance and Chennai Mathematical Institute's B.Sc. Math Entrance. They ranked within the first 200 in the entire country in these entrances. Most of these students attended the problem solving workshops regularly, which happen 5 days every week. CMI B.Sc. Math Entrance […]
the expected value in uniform should be 5000.
It is written that N= U +1. But after that , it is written E(N) = E( U ) ? Isn't should be "E(N) = E( U ) +1"?