Algebraic structure of some stochastic discrete event systems, with applications