Why are std::shuffle methods being deprecated in C++14?

Trevor Hickey picture Trevor Hickey · Mar 24, 2014 · Viewed 9.8k times · Source

According to the cppreference.com reference site on std::shufle, the following method is being deprecated in c++14:

template< class RandomIt >
void random_shuffle( RandomIt first, RandomIt last );

Why will we no longer be able to call the following function without passing a third parameter?

std::random_shuffle(v.begin(),v.end()); //no longer valid in c++14

It doesn't appear as though a different function deceleration has a default parameter set. What is the reason behind this? Was there some kind of alternative added?

Answer

Germ&#225;n Diago picture Germán Diago · Mar 24, 2014

std::random_shuffle may make use, under the hood, of random C family of functions. These functions use global state for seeds and other state.

So it is being deprecated because shuffle will do the same, but better. Namely, it uses the new <random> header from C++11 that doesn't use global state, but its own objects making use of generators, devices and distributions.