Stochastic accretion of planetesimals on to white dwarfs: constraints on the mass distribution of accreted material from atmospheric pollution