Instead of choosing the last element of every sub array as the pivot, we choose a random element in Randomized version and swap it with the last element before partitioning.
public static void RandomizedQuickSort(int[] input, int left, int right) { if (left < right) { int q = RandomizedPartition(input, left, right); RandomizedQuickSort(input, left, q - 1); RandomizedQuickSort(input, q + 1, right); } }