What is the difference between shuffle and random_shuffle c++

爱⌒轻易说出口 提交于 2019-12-03 10:40:34

If you read the documentation at cppreference.com closely, you will find that the RandomFunc passed to random_shuffle has a different interface. It is invoked as r(n). This existed before C++11.

std::shuffle uses a standardized way of getting random numbers and invokes g(). This standardized random number generators where introduced with C++11 together with std::shuffle.

Nawaz

std::random_shuffle uses std::rand() function to randomize the items, while the std::shuffle uses urng which is a better random generator, though with the particular overload of std::random_shuffle, you can get the same behavior (as with the std::shuffle) but that requires you to do some work to pass the third argument.

Watch this talk by Stephan T. Lavavej, in which he explains why std::rand is a bad function and what C++ programmers should use instead:

The gist is, std::shuffle is an improvement over std::random_shuffle, and C++ programmers should prefer using the former.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!