Improve randomized algorithm