Two-photon photoassociation of hot magnesium atoms by femtosecond laser pulses, creating electronically excited magnesium dimer molecules, is studied from first principles, combining ab initio quantum chemistry and molecular quantum dynamics. This theoretical framework allows for rationalizing the generation of molecular rovibrational coherence from thermally hot atoms [L. Rybak et al., Phys. Rev. Lett. 107, 273001 (2011)]. Random phase thermal wave functions are employed to model the thermal ensemble of hot colliding atoms. Comparing two different choices of basis functions, random phase wavefunctions built from eigenstates are found to have the fastest convergence for the photoassociation yield. The interaction of the colliding atoms with a femtosecond laser pulse is modeled non-perturbatively to account for strong-field effects.