Stochastic algorithms in electromagnetic optimization