codes for a simulation