The random string loop problem asks for the discrete distribution of the number of closed loops formed from
open strings by repeatedly choosing two distinct loose ends
uniformly at random and tying them together (Blitzstein and Hwang 2014, p. 183).
The sequence of ties gives a uniformly random perfect
matching of the
original ends. There are
such matchings,
where
is a double factorial.
When
open strings remain, exactly one of the
possible partners of the first chosen end closes a loop.
Each tie reduces the number of open strings by one, whether it closes a loop or joins
two strings into a single open string. Since the conditional
probability of closing a loop is
for every history of the preceding ties, the loop closure
events are independent.
The expectation value is
|
(1)
|
where
is a harmonic number. For 50 strings, the expectation
value is approximately 2.93777 (3Blue1Brown 2026).
The probability generating function of
is
|
(2)
|
Expanding the numerator and using the unsigned Stirling numbers of the first kind gives the probability
mass function
|
(3)
|
for , with probability
zero otherwise. For
,
the probability of
is 1. The numerator counts the matchings
that give
loops. For
, the counts for
,
,
, and
are
,
,
,
and
(OEIS A039683, absolute values of row 4).