Removed std::random_shuffle
This lessons will provide a better alternative to random_shuffle.
The random_shuffle(first, last)
and random_shuffle(first, last, rng)
functions were marked already as deprecated in C++14. The reason was that in most cases it used the rand()
function, which is considered inefficient and even error-prone (as it uses global state). Alternatively, you could provide the rng
function parameter that appeared to be unusable in practice. If you need the same functionality, use std::shuffle
:
template< class RandomIt, class URBG >
void shuffle( RandomIt first, RandomIt last, URBG&& g );
std::shuffle
takes a random number generator as the third template argument, which is safer, easier to use and more scalable.
Have a look at the following example on how to convert from random_shuffle
to shuffle
:
Get hands-on with 1400+ tech skills courses.