function foo(n)
if n = 1 then
return 1
else
return foo(rand(1, n))
end if
end function
If foo is initially called with m as the parameter, what is the expected number times that rand() would be called ?
BTW, rand(1,n) returns a uniformly distributed random integer in the range 1 to n.
If $N(n)$ is the expected number of calls to foo, then for $n>1$ $$N(n) = 1 + \frac{N(1)+N(2)\cdots N(n)}{n} \Rightarrow N(n) =\frac{n}{n-1} +\frac{N(1)+N(2)\cdots N(n-1)}{n-1} $$ because each recursive call passes a random argument between 1 and $n$.
Starting with $N(1)$, calculate $N(2)$ etc to see the pattern.
The number of calls to rand is one less than the number of calls to foo.