A stochastic model of the emergence of autocatalytic cycles