Reputation: 60361
If you look to the specifications of random shuffle in C++11, there are 3 functions. My question is what is the typical use and advantage of :
template< class RandomIt, class URNG >
void shuffle( RandomIt first, RandomIt last, URNG&& g );
compared to:
template< class RandomIt >
void random_shuffle( RandomIt first, RandomIt last );
I mean, it seems that whatever URNG is (a uniform distribution), the result will be the same (from a statistical point of view). The only point I see, is that std::shuffle
is thead-safe, whereas this overload ofstd::random_shuffle
is not. Could you confirm that ?
EDIT: I thought that URNG should be a uniform distribution but that does not seem to compile. So can someone provide a little example of use of std::shuffle
?
Upvotes: 4
Views: 1578
Reputation: 14421
As mentioned in the comments, std::shuffle
takes a random number generator (or engine in standard speak), not a random number distribution. Different random number generators have different characteristics even if they have a theoretically uniform distribution.
For an overview of the different generators offered by the standard, please refer to http://en.cppreference.com/w/cpp/numeric/random.
Upvotes: 2