implement random partition algorithm