New Monte Carlo method for Compton and Rayleigh scattering by polarized gamma rays