Some doubts in C++

I have following doubts:
1)Why do we use randomized quick sort?
2)Inside the for loop of shuffle function why did Bhaiya write
j=rand()%(i+1);
why is he taking modulo with i+1 ? It should be i only because we need the random index between 0 to i-1 ?

Randomized quicksort has a better worst case time complexity comapared to the normal quicksort.
The worst case of a normal quicksort is O(n^2) when the elements are already sorted.
So we randomize or shuffle the array before sorting to avoid the worst case complexity. This would reduce the worst case to O(n log n).
We are taking modulo with i+1 because it will pick a random index from 0 to i for the swap. If it picks i, it means it will swap with itself( ie. no actual swapping will occur for that index). You can also take j=rand()%(i);

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.