Optimal Control Of Random Sequences In Problems With Constraints