Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Is there anything that can be said about how many attempts it will take to correctly guess a random number out of 1000 numbers? If the number wouldn't change the probability would just increase every guess, giving in the end a probability of 1.

If the number changes every guess tough, you just have a 1/1000th chance everytime. Can it be calculated how many attempts it would probably take, on average?

(I'm sorry, i'm not very skilled in probability maths)

share|improve this question
add comment

3 Answers 3

up vote 3 down vote accepted

This concept is the foundation of the Law of Large Numbers, which is behind most concepts of probability. By definition, if given 1000 unique random trials, a particular event (result) occurs once, then the observed probability of that event occurring is 1/1000. The inverse is basically the application of the calculated probability; if an event has a probability of 1/1000, then if you performed 1000 trials, you should expect the event to occur once. For an independent event (the results of past trials do not influence the probability of future ones), it's not guaranteed to happen exactly once per 1000 trials, but as the number of trials t grows large, the number of times an event with probability $1/n$ occurs will approach $t/n$.

Now, if you started with the first trial, and continued performing trials until the event occurred, and then counted how many trials it took, the probability of it occurring for the first time on exactly the Xth trial is equal to the probability that it doesn't occur on any of the X-1 trials, and that it does occur on the Xth. The probability that it doesn't happen is $\dfrac{n-1}{n}$ (or equivalently $1-\dfrac{1}{n})$ and it must happen X-1 times, followed by the event occurring the Xth time ($1/n$ probability), so the formula for the probability of it occurring on exactly the Xth trial is

$$P(X)=(1-\dfrac{1}{n})^{X-1}(\dfrac{1}{n})$$

Plugging in our known specific value for N, we get:

$$P(X)=(\dfrac{999}{1000})^{X-1}(\dfrac{1}{1000})$$

This is an asymptotically-reducing exponential function; it approaches zero as X grows infinitely large. As such, there isn't a point at which it starts becoming more likely to happen; it just becomes increasingly less likely that it doesn't happen. However, if we consider only how likely it is that it doesn't happen in X-1 trials ($(\dfrac{999}{1000})^{X-1}$), we can find an "over-under", where it is equally likely for it to take more than that many trials than fewer. This is our "expected value" for the number of trials it should take (similar to the "expected value" of one roll of the dice; the probability that it's greater than or equal to a certain face value is 1 at 1, but only 1/6 at 6, and at the expected value of 3.5, the odds are 50-50 either way). With a little graphing magic, we see that the number of trials after which the probability of your number having not occurred so far drops below .5 is 674.

Thus, before you begin choosing numbers, you can expect it to take, on average, about 674 trials for the number you want to pop up for the first time. However, there's still a 36% chance it won't happen in 1000 trials, and a 13% chance it won't even happen once in 2000 trials, and given that it hasn't happened in 674 trials (or 1000 or even 100,000), the probability the next number will be the one you want is still 1 in 1000.

share|improve this answer
    
The question was how many attempts it takes on average. –  copper.hat Sep 20 '12 at 19:06
    
Substantial edit to answer the question actually asked instead of the title question. –  KeithS Sep 20 '12 at 21:15
add comment

Let $K$ be the number of attempts it takes. You want to compute the expected value of $K$, that is $E[K]$. Since this is a discrete distribution, we have $E[K] = \sum_{k=1}^\infty k p_k$, where $p_k$ is the probability that it takes exactly $k$ attempts to guess the correct number.

Fixed number: If the number is fixed, then the expected number is straightforward to compute. Note that $p_k = 0$ for $k > 1000$, since you must have figured out the number by then (I'm assuming that guesses are not repeated!). To compute $p_k$ for $k \leq 1000$, we need the probability of making $k-1$ incorrect guesses (without 'replacement'), multiplied by the probability of the $k$th guess being correct, ie, $p_k = \frac{1000 - 1}{1000 - 0} \frac{1000 - 2}{1000 - 1} \cdots \frac{1000-(k-1)}{1000-(k-2)} \frac{1}{1000-(k-1)} = \frac{999}{1000} \frac{998}{999} \cdots \frac{1000-k+1}{1000-k+2} \frac{1}{1000-k+1} = \frac{1}{1000}$. Consequently, $E[K] = \frac{1}{1000} \sum_{k=1}^{1000} k = \frac{1001}{2}$. That is, on average you would expect to take 500.5 attempts.

Changing number: If the number is randomly selected from 1,000 numbers each time, the expected number of attempts is straightforward to compute.

In this case $p_k = (1-\theta)^{k-1}\theta$, where $\theta = \frac{1}{1000}$. So the answer is $E[K] = \sum_{k=1}^\infty k (1-\theta)^{k-1}\theta$.

Since $\sum_{k=1}^\infty k (1-\theta)^{k-1} = \frac{1}{\theta^2}$, this gives $E[K] = \frac{1}{\theta} = 1000$. That is, on average you would expect to take 1000 attempts.

share|improve this answer
    
+1 for nicely addressing the actual question. The part you didn't answer was the expected value if you always pick a different number between 1 and 1000 (e.g. random sampling without replacement). I see that the question could be interpreted as not asking this but the case was mentioned and the OP did mention that the probability would increase to 1 as n approaches 1000 (assuming it is the conditional probability of success on trial k given failure on all previous trials). –  Michael Chernick Sep 20 '12 at 20:27
    
@MichaelChernick: Thanks! The OP mentioned that (in the changing case) that the probability of a correct guess would be $\frac{1}{1000}$ 'everytime' [sic.] so I presumed that meant with replacement... –  copper.hat Sep 20 '12 at 20:32
    
I see. 1/1000 would not be correct everytime given sampling without replacement. –  Michael Chernick Sep 20 '12 at 20:36
    
@MichaelChernick: Without replacement it is possible that you many never guess the number (assuming that you don't know the discards), in which case the expected length is undefined (or infinite, depending on your interpretation). If you know the discards, then I think this reduces to the 'fixed number' case (I haven't thought this through completely). –  copper.hat Sep 20 '12 at 20:42
    
@copper.hat: the expected length is not undefined since, while it's strictly possible that you'd never guess the number, the probability is zero (you almost surely guess the number). –  Ben Millwood Sep 20 '12 at 20:56
show 4 more comments

As you said, if the number doesn't change while you're guessing, and you always guess a number that you haven't guessed yet, then your probability of getting the number right within $m \le n$ guesses is just $m/n$. To make the probability of getting it right reach $p$, you need $m(p)=pn$ guesses.

On the other hand, if the number changes after every guess, then your probability of getting it wrong is $1-1/n$ for each guess (independent of how many guesses you've made already), and your probability of getting it wrong $m$ consecutive times is $$\left(1-\frac{1}{n}\right)^{m} \sim \exp\left(-\frac{m}{n}\right),$$ where the approximation is asymptotically valid as $n\rightarrow\infty$. Here, to make the probability of getting it right reach $p$, you need $$ m(p)=-n\log(1-p)=pn+\frac{1}{2}p^2n+\frac{1}{3}p^3n + \ldots $$ guesses. Note that this is approximately equal to $pn$ for small $p$, but for $p$ approaching $1$ (i.e., to achieve certainty), you need a divergent number of guesses.

share|improve this answer
    
The question was how many attempts it takes on average. –  copper.hat Sep 20 '12 at 19:07
    
I gave a +1 for an interesting answer even though technically it is not an answer to the question and a purist would downvote it. copper.hat is right! –  Michael Chernick Sep 20 '12 at 20:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.