This paper puts forward an improved particle swarm algorithm in order to improve the efficiency of autogenerating test paper. The paper conducts mathematically modeling based on item response theory. In the new algorithm, the inertia weight is expressed as functions of particle evolution velocity and particle aggregation by defining particle evolution velocity and particle aggregation so that the inertia weight has adaptability. At the same time, slowly varying function is introduced to the traditional location updating formula so that the local optimal solution can be effectively overcome. Simulation results show that compared with the quantum-behaved particle swarm algorithm, the proposed algorithm has better performance in success rate and composing efficiency.