Thermalization of random nonlinear waves: Application to optical waves