Generation of runaway electrons during the thermal quench in tokamaks