TITLE: average length of "harmonic walk" mod $n$ is $\ln(n)$ -- why?
QUESTION [8 upvotes]: Let a harmonic walk be a stochastic process where at turn $t \ge 2$ the probability of ending the walk is $\frac{1}{t}$ and the first turn never ends the walk. A harmonic walk can be viewed as a distribution over $\mathbb{N}_{\ge 1}$ without finite mean.
Empirically, it seems to be the case that the average length of a harmonic walk mod $n$ is $\ln\left(n\right)$ . I'm wondering why this should be the case. The definition of the harmonic series (1) looks similar to the integral definition of the natural log, $\ln(x) \stackrel{\text{def}}{=} \int_{1}^{x} 1/s \;\text{ds} $, so there might be reason to suspect that a relationship might exist, but that resemblance isn't remotely convincing.
The harmonic series $H$ is given below (1) with the symbol "$H$" referring to the formal sum, not the value.
$$ H \stackrel{\text{def}}{=} \sum_{k=1}^{\infty} \frac{1}{k} \;\;\;\;\;\;\;\;\text{and $H$ diverges} \tag{1} $$
We can write an equivalent formal sum of partial products $H'$ (2a). I don't know the exact term for the relationship between $H$ and $H'$ as formal expressions, but $\frac{1}{k}$ is finite and definitely equal to $\prod_{l=2}^{k} \frac{l-1}{l} $.
$$ H' \stackrel{\text{def}}{=} \sum_{k=1}^{\infty} \prod_{l=2}^{k} \frac{l-1}{l} \tag{2a} $$
$$ H' = 1 + \left(\frac{1}{2}\right) + \left(\frac{1}{2} \times \frac{2}{3} \right) \dots \tag{2b} $$
Squinting at the definition of $H'$, we can come up with a stochastic process $\Psi$ .

At every turn in $\Psi$, we either stop immediately or add 1 to $t$ .
If $t = 1$, then advance to the next turn with probability $1$.
If $t \ne 1$, then stop with probability $\frac{1}{t}$ and continue to the next turn with probability $\frac{t-1}{t}$ .

If we take the output of $\Psi \;\;\text{mod}\;\; n$ for various values of $n$, it seems to match $\ln\left(n\right)$ .
n        Ψ mod n     ln(n)
2          0.693     0.693
3          1.099     1.099
4          1.386     1.386
5          1.609     1.609
6          1.793     1.792
7          1.947     1.946

Why should this be the case?

Here is the python code used to produce samples:
import random
import math
import os

STOP = "STOP"
GO   = "GO"

def step(n):
    assert (n > 1)
    if random.randint(1, n) == 1:
        return STOP
    else:
        return GO


def walk_length():
    n = 2
    len_ = 1
    while GO == step(n):
        len_ += 1
        n += 1
    return len_


for x in range(1000000):
    print(walk_length() % int(os.getenv("MODULUS")))

and the summary script from here:
#! /bin/sh

Rscript -e 'summary (as.numeric (readLines ("stdin")));'

A sample run.
> env MODULUS=7 python process_steps.py | summary 
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.000   1.000   1.000   1.947   3.000   6.000

REPLY [5 votes]: We have
$$\operatorname P[L = n] =
\frac 1 2 \frac 2 3 \cdots \frac {n - 1} n \frac 1 {n + 1} =
\frac 1 {n (n + 1)} [n \geq 1], \\
\operatorname P[(L \bmod m) = n] =
\sum_{k \geq 0} \operatorname P[L = m k + n] \,[0 \leq n < m], \\
\operatorname E[L \bmod m] =
\sum_{0 < n < m} \sum_{k \geq 0} \frac n {(m k + n) (m k + n + 1)} = \\
\sum_{0 < n < m} \frac n m
 \left(
  \psi {\left( \frac {n + 1} m \right)} - \psi {\left( \frac n m \right)}
 \right) = \\
\psi(1) - \frac 1 m \sum_{0 < n \leq m} \psi {\left( \frac n m \right)} =
\ln m.$$
The last identity follows from
$$\Gamma(m z) = m^{m z - 1/2} (2 \pi)^{(1 - m)/2}
 \prod_{0 < n \leq m} \Gamma {\left( z + \frac {n - 1} m \right)}.$$