A molecular dynamics simulation method which can generate con®gurations belonging to the canonical ...T , V , N† ensemble or the constant temperature constant pressure ...T , P, N† ensemble, is proposed. The physical system of interest consists of N particles (f degrees of freedom), to which an external, macroscopic variable and its conjugate momentum are added. This device allows the total energy of the physical system to uctuate. The equilibrium distribution of the energy coincides with the canonical distribution both in momentum and in coordinate space. The method is tested for an atomic uid (Ar) and works well.