Study on discrete space charge effects in electron beams and guns