Stochastic approach to maximization of a functional constrained by governing equation of a controlled system is introduced and discussed. The idea of the proposed algorithm is the following: represent the functional to be maximized as a limit of a probability density governed by the appropriately selected Liouville equation. Then the corresponding ODE become stochastic, and that sample of the solution which has the largest value will have the highest probability to appear in ODE simulation. Application to optimal control is discussed. Two limitations of optimal control theory - local maxima and possible instability of the optimal solutions - are removed. Special attention is paid to robot motion planning.