We describe an implementation of the Andersen algorithm for simulating the
molecular dynamics in the isobaric isoenthalpic (NPH) ensemble for the hard
sphere potential. The work is based on the adaptation of the Andersen algo
rithm to hard spheres by de Smedt et al. For a hard sphere system in the NP
H ensemble, the particle velocities are not constant between collisions and
we describe an efficient method for handling this part of the dynamics. Th
e method is extended to give an NPT ensemble simulation of hard sphere syst
ems by applying an ad hoc rescaling of the velocities. The accuracy of the
algorithms is tested by comparison with traditional NVE simulation results
for the structural, thermodynamic, and transport properties.