markov chain algorithm implemented