Average Length of Random Number Generation with Decreasing Range of Numbers
Consider a game where one would roll a random integer between $1$ and $N_0$ where $N_0 \ge 1$. The newly randomly generated number is now the new "upper limit" of the game, the game continues by rolling a random number between $1$ and the randomly generated number. This game continues until the randomly generated number is 1.
Here is an example of how it can look like. Consider $N_0 = 1000$
$$N_1 = Random(1, N_0) = Random(1, 1000) = 623$$ $$N_2 = Random(1, N_1) = Random(1, 623) = 366$$ $$N_3 = Random(1, N_2) = Random(1, 366) = 303$$ $$N_4 = Random(1, N_3) = Random(1, 303) = 190$$ $$N_5 = Random(1, N_4) = Random(1, 190) = 52$$ $$N_6 = Random(1, N_5) = Random(1, 52) = 13$$ $$N_7 = Random(1, N_6) = Random(1, 13) = 1$$ $$END$$
The Length of the example game was 7, it took 7 rolls to reach 1.
Given the Starting Upper Limit $N_0$, what is the average amount of rolls needed to reach 1?
I have tried to write Python code to help with this problem and it seems this follows a Logarithmic Pattern with the function to approximate the amount is $f(N_0) = 1.0168287465013466\ln(N_0) + 1.4731706151125865$
Solution 1:
There is one chance in $N_0$ of rolling $N_0$ and otherwise it is the same as if you started with $N_0-1$. So
$$f(N_0)=\frac1{N_0}(1+f(N_0))+\frac{N_0-1}{N_0}f(N_0-1)\\
=\frac1{N_0-1}+f(N_0-1)$$
So it is the harmonic series.