easy way to randomize the entries of an array usin

2019-06-24 14:13发布

问题:

I can sort a int* array using stl, plain and simple like

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

Is there any equal simple way to randomize it?

thanks

回答1:

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



回答2:

If you want to generate new random content instead of shuffling the elements that are already there:

std::generate_n(myarray, size, &std::rand);