A realistic simulation of a magnetic recording medium necessitates the use of a realistic grain microstructure. However, the calculation of the demagnetizing field for irregular structures is difficult. In this article an approach to the calculation of demagnetizing tensors is described which allows for the use of arbitrary microstructures and also allows nonmagnetic grain boundaries to be included in the model. Simulations of media with various grain size distributions are described. A narrower distribution of grain sizes results in higher signal-to-noise ratios for recorded tracks and increased resistance to stray fields.