Monte Carlo inversion of hydrogen and metal lines from QSO absorption spectra