The expected number of loops for 50 strings is 2.94
With 50 strings and every loose end tied at random, you end up with about 2.94 loops on average. The math is three lines, the PHP simulation fits in one function, and the obvious port from Python is the slow way to build it.