Better random algorithm.