Is there any way to randomly swap two elements (two different index) in an array in C++? My idea is to randomly pick the first index, then randomly pick the second one till the second index is different from the first index. Then swap these two elements. I am wondering is there any better way to do this?
I think this is different from random_shuffle because each time I only want to swap two elements in the array and keep others in the original order.
Aucun commentaire:
Enregistrer un commentaire