Diffraction by gratings: from the C-method to the stochastic C-method