Simulation of temporal second-order correlation function based on Monte Carlo algorithm