开发者

easy way to randomize the entries of an array using stl?

开发者 https://www.devze.com 2022-12-19 13:02 出处:网络
I can so开发者_如何学运维rt a int* array using stl, plain and simple like std::sort(myarray, myarray + size);

I can so开发者_如何学运维rt a int* array using stl, plain and simple like

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

Is there any equal simple way to randomize it?

thanks


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


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

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

精彩评论

暂无评论...
验证码 换一张
取 消