simplified the rand_partition algorithm