improved random_chain

now it uses iteration instead of recursion, and is guaranteed
to finish due to backtracking.
removed ugly printing