Why is it a good idea to choose a random pivot when using quicksort?
I've been looking at different implementations of quicksort with different ways of optimizing it. One of the optimizations that is really confusing is the idea of choosing the pivot randomly. It just seems counter intuitive to me that randomly choosing a pivot would lower the probably of achieving the worst case scenario(if you already have a sorted array as a simple case). The idea of choosing the best pivot is to divide the array into equally balanced sub arrays so that you dont run into the scenario where there is nothing to the left or right side of the pivot(this is the case when you a sorted array or a reverse sorted array and cause quicksort to run in big-oh n^2). If that is the case, why not just make the middle of the array the pivot? If someone can explains this better to me that would be great.