You're thinking of Markov chains.