The paper describes a method of solving some stochastic processes using generating functions. A general theorem of generating functions of a particular type is derived. A generating function of this type is applied to a stochastic process yielding polynomial time algorithms for certain partitions. The method is generalized to a stochastic process describing a rather general linear transform. Finally, the main idea of the method is used in deriving a theoretical polynomial time algorithm to the knapsack problem.