Any way to recreate this procedurally and random?
It may be possible to extract the right information from Blender's own Voronoi texture, but you'd have to call it twice, and I'm not sure it would save any nodes. (Someone will correct me now...)
So this is a roll-your-own 1D Voronoi. That is to say, it is per-cell random, not full-space random. The method:

Divide X into unit cells
Seed a random 0-1 number for each cell using the cell's index (its minimum coordinate).
Consider the random number to be the offset of a feature-point F for that cell, from its minimum X.

Now, for any shading-point P, we know the location of F in its own cell, and the location of the feature-point F' in the previous cell. That's enough.
If we're to the right of F, then f(x) =  P.x - F.x . If we're to the left of F, f(x) = P.x - F'.x.
That all takes more plumbing than you might expect, and unhelpfully, in the illustration, I've called F P_this, and F' P_prev:

You may be able to trim it down..