Stochastic theory of magnetic resonance