shuffle和random_shuffle c ++之间的区别是什么 [英] What is the difference between shuffle and random_shuffle c++
问题描述
函数 std :: shuffle 已在C ++ 11中引入:
The function std::shuffle has been introduced in C++11:
template< class RandomIt, class URNG >
void shuffle( RandomIt first, RandomIt last, URNG&& g );
,它具有与 std::random_shuffle 这也是在C ++ 11中引入的:
and it has the same signature as one of the overloads of std::random_shuffle which was also introduced in C++11:
template< class RandomIt, class RandomFunc >
void random_shuffle( RandomIt first, RandomIt last, RandomFunc&& r );
区别在于第三个参数,其中:
The difference is in the third parameter where:
URNG必须符合UniformRandomNumberGenerator的要求
URNG must meet the requirements of UniformRandomNumberGenerator
这是全部吗?是不是只是 shuffle
执行额外的编译时检查?
Is this all? Is the difference just that shuffle
performs an extra compile time check? Is the behavior otherwise the same?
推荐答案
如果您仔细阅读cppreference.com上的文档,您会发现传递给
具有不同的接口。它被作为 Random_shuffle
的RandomFunc r(n)
调用。这存在于C ++ 11之前。
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
使用一种标准化的方式获取随机数和调用 g()
。这个标准化的随机数生成器引入了C ++ 11和 std :: shuffle
。
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
.
这篇关于shuffle和random_shuffle c ++之间的区别是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!