The results of a numerical simulation of the generation of runaway electrons in pressurized nitrogen and helium gases are presented. It was shown that runaway electrons generation occurs in two stages. In the first stage, runaway electrons are composed of the electrons emitted by the cathode and produced in gas ionization in the vicinity of the cathode. This stage is terminated with the formation of the virtual cathode, which becomes the primary source of runaway electrons in the second stage. Also, it was shown that runaway electrons current is limited by both the shielding of the field emission by the space charge of the emitted electrons and the formation of a virtual cathode. In addition, the influence of the initial conditions, such as voltage rise time and amplitude, gas pressure, and the type of gas, on the processes that accompany runaway electrons generation is presented.