markov chain function