  A new algorithm is presented, which allows to calculate numerically the
partition function Z_q of the d-dimensional q-state Potts models for arbitrary
real values q>0 at any given temperature T with high precision. The basic idea
is to measure the distribution of the number of connected components in the
corresponding Fortuin-Kasteleyn representation and to compare with the
distribution of the case q=1 (graph percolation), where the exact result Z_1=1
is known.
  As application, d=2 and d=3-dimensional ferromagnetic Potts models are
studied, and the critical values q_c, where the transition changes from second
to first order, are determined. Large systems of sizes N=1000^2 respectively
N=100^3 are treated. The critical value q_c(d=2)=4 is confirmed and
q_c(d=3)=2.35(5) is found.
