Made a randomized n^2 algorithm