A non convex optimization problem, involving a regular functional J, on a closed and bounded subset S of a separable Hilbert space V is here considered. No convexity assumption is introduced. The solutions are represented by using a closed formula involving means of convenient random variables, analogous to Pincus (Oper Res 16(3):690–694, 1968). The representation suggests a numerical method based on the generation of samples in order to estimate the means. Three strategies for the implementation are examined, with the originality that they do not involve a priori finite dimensional approximation of the solution and consider a hilbertian basis or enumerable dense family of V. The results may be improved on a finite‐dimensional subspace by an optimization procedure, in order to get higher‐quality solutions. Numerical examples involving both classical situation and an engineering application issued from calculus of variations are presented and establish that the method is effective to calculate.