#include <random>
#include <algorithm>
#include <vector>
int main() {
std::vector < int > a = {1, 2, 3};
std::mt19937 generator;
std::random_shuffle(a.begin(), a.end(), generator);
}
I am trying to compile this code with g++ -std=c++0x, receiving a huge compiler dump ending with
/usr/include/c++/4.9.2/bits/random.h:546:7: note: candidate expects 0 arguments, 1 provided
Any way of doing it correctly?
The overload of std::random_shuffle
you're trying to use takes a "RandomFunc":
function object returning a randomly chosen value of type convertible to
std::iterator_traits<RandomIt>::difference_type
in the interval [0,n) if invoked as r(n)
In C++14, std::random_shuffle
is deprecated in favour of std::shuffle
, which takes a generator rather than that "RandomFunc". Simply change the function to std::shuffle
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With