Rationale Knudsen effusion mass spectrometry (KEMS) shows improved performance with the ‘restricted collimation’ method of Chatillon and colleagues, which consists of two apertures between the Knudsen cell orifice and the ionizer. These apertures define the shape and position of the molecular beam independently of the sample and effusion orifice and as a result reduce background and improve sampling from the Knudsen cell. Modeling of the molecular beam in restricted collimation allows optimization of the apertures' diameters and spacing. Methods Knudsen flow is easily simulated with a Monte Carlo method. In this study a Visual Basic for Excel (VBA) code is developed to simulate the molecular beam originating from a vaporizing condensed phase in a Knudsen cell and passing through the cell orifice and the two apertures. Results The code is able to calculate the transmission coefficient through the cell orifice, through the cell orifice and the first aperture, and through the cell orifice and first and second apertures. Also calculated are the angular distributions of the effusate density emerging from the cell and average number of collisions with the orifice walls. Conclusions This code allows the geometry (aperture spacing and diameters) of the sampling system to be optimized for maximum transmission. The calculated effusate distributions and low average number of orifice wall collisions illustrated the advantages of restricted collimation. Calculated transmission factors are also compared to literature values calculated via the analytical method of Chatillon and colleagues. Published in 2017. This article is a U.S. Government work and is in the public domain in the USA.