Small-angle x-ray and neutrons scattering is a widespread experimental tool for the investigation of the microstructure of random heterogeneous materials. Validation of (computer-generated) model microstructures often requires the numerical computation of the scattering intensity, which must be carried out with great care due to finite size effects. In this paper, a new method for this computation is presented. It is superior to previously existing methods for three reasons: First, it applies to any type of microstructure (not necessarily granular). Second, closed-form expressions of the size effects inherent to the proposed method can be rigorously derived and removed (in this sense, our method is free of size effects). Third, the complexity of the new algorithm is linear and the computation can easily be updated to account for local changes of the microstructure, while most existing algorithms are quadratic and any change of the microstructure requires a full recomputation. The present paper provides full derivation and validation of this method. Application to the computation of the scattering intensity of dense, polydisperse assemblies of spheres is then presented. A new, simple algorithm for the generation of these dense configurations is introduced. Finally, the results are critically reviewed in the perspective of hardened cement pastes.