Easy way to randomize array entries with stl?

I can sort an int * array using stl as simple and simple as

std::sort(myarray, myarray + size); 

Is there an easy way to randomize it?

thanks

+4
source share
2 answers

std::random_shuffle (myarray, myarray + size);

+17
source

If you want to create new random content instead of shuffling those elements that already exist:

 std::generate_n(myarray, size, &std::rand); 
+7
source

Source: https://habr.com/ru/post/1300437/


All Articles