The Random Energy Model of statistical physics is applied to the problem of the specificity of recognition between two biological (macro)molecules forming a non-covalent complex. In this model, the native mode of association is separated by an energy gap from a large body of non-native modes. Whereas the native mode is unique, the non-native modes form an energy spectrum which is approximated by a gaussian distribution. Specificity can then be estimated by writing the partition function and calculating the ratio r of non-native to native modes at thermodynamic equilibrium. We examine three situations: (i) recognition in the absence of a competitor; (ii) recognition in the presence of a competing ligand; (iii) recognition in a heterogeneous mixture. We derive the dependence of the ratio r on temperature and on the concentration of competing ligands, and we estimate the effect of a local perturbation such as can result from a point mutation. Cases (i) and (iii) are modeled by docking experiments in the computer. In case (iii), which is representative of a wide variety of biological situations, we show that increasing the heterogeneity of a mixture affects the specificity of recognition, even when the concentration of competing species is kept constant.