Gyrotrons are the leading microwave sources for plasma heating and current drive in magnetic confinement fusion experiments. In a gyrotron, a helical electron beam, guided by an external magnetic field, delivers energy to a RF electromagnetic wave (i.e. a TE mode supported by the interaction cavity) through electron cyclotron resonance. Computer simulations of the beam-field interaction in gyrotrons play a very important role in their design. The usual approach in such simulations is to model the electron beam as several ensembles of electrons entering the interaction region at times t0, t0 + Deltat, t0 + 2Deltat etc. The electrons of each ensemble differ in the direction of their initial transverse velocity, in the azimuthal position of their guiding center and, when a non-ideal beam is studied, in their guiding center radius and in their initial energy and transverse to parallel velocity ratio. The key issue is that, at each time step, only the contribution of the corresponding ensemble passing through the interaction cavity is taken into account. We have observed that this approach can sometimes lead to a numerically enforced excitation of parasitic modes that affect the results considerably. This is so because the necessary averaging over the electron entrance time is not always performed correctly, and this is chiefly apparent when the averaging over the azimuthal position of the guiding center has no effect on certain combinations of modes. We propose an alternative way of modeling the electron beam, that is, by considering it as a set of electrons distributed throughout the cavity and moving toward the exit, rather than a sequence of "independent" ensembles entering the cavity every Deltat. The new modeling is closer to reality, ensuring thus correct time averaging, and it moreover does not rely on the usual assumption that the electron transit time is quite smaller than the characteristic time of the evolution of the RF field.