A model first used to describe hydrogen isotope trapping and replacement in the wall of pinch discharges is extended to tokamak discharges including pulsed gas inlet. It calculates the trapped-particle density in the walls versus time as a function of trapping coefficient, replacement cross-section, geometrical factors, particle confinement time and cold-gas influx. The solutions are used to describe the development of the average electron density and yield criteria for the conditions under which the plasma density falls or rises during a discharge. The model also allows a distinction between plasma/limiter and plasma/first-wall interaction. A comparison with measurements from tokamak discharges is made.