Stochastic version of the Erdos-Renyi limit theorem