  A new method, based on simulated annealing technique and aimed at the inverse
problem in the analysis of intergalactic or interstellar complex spectra of
hydrogen and metal lines, is outlined. We consider the process of line
formation in clumpy stochastic media accounting for fluctuating velocity and
density fields self-consistently. Two examples of the analysis of `H+D'-like
absorptions seen at z = 3.514 and 3.378 towards APM 08279+5255 are presented.
