Abstract : A stochastic algorithm is proposed, finding the set of generalized means associated to a probability measure on a compact Riemannian manifold M and a continuous cost function on the product of M by itself. Generalized means include p-means for p>0, computed with any continuous distance function, not necessarily the Riemannian distance. They also include means for lengths computed from Finsler metrics, or for divergences. The algorithm is fed sequentially with independent random variables Y_n distributed according to the probability measure on the manifold and this is the only knowledge of this measure required. It evolves like a Brownian motion between the times it jumps in direction of the Y_n. Its principle is based on simulated annealing and homogenization, so that temperature and approximations schemes must be tuned up. The proof relies on the investigation of the evolution of a time-inhomogeneous L^2 functional and on the corresponding spectral gap estimates due to Holley, Kusuoka and Stroock.