We study the effect of the head shape variations on the EEG/magnetoencephalography (MEG) forward and inverse problems. We build a random head model such that each sample represents the head shape of a different individual and solve the forward problem assuming this random head model, using a polynomial chaos expansion. The random solution of the forward problem is then used to quantify the effect of the geometry when the inverse problem is solved with a standard head model. The results derived with this approach are valid for a continuous family of head models, rather than just for a set of cases. The random model consists of three random surfaces that define layers of different electric conductivity, and we built an example based on a set of 30 deterministic models from adults. Our results show that for a dipolar source model, the effect of the head shape variations on the EEG/MEG inverse problem due to the random head model is slightly larger than the effect of the electronic noise present in the sensors. The variations in the EEG inverse problem solutions are due to the variations in the shape of the volume conductor, while the variations in the MEG inverse problem solutions, larger than the EEG ones, are caused mainly by the variations of the absolute position of the sources in a coordinate system based on anatomical landmarks, in which the magnetometers have a fixed position.