Implement random contraction algorithm