std::experimental::shuffle - cppreference.com
From cppreference.com
template< class RandomIt > void shuffle( RandomIt first, RandomIt last ); |
(library fundamentals TS v2) | |
Reorders the elements in the given range [first, last) such that each possible permutation of those elements has equal probability of appearance, using the per-thread random number engine as the random number generator.
Parameters
Return value
(none)
Complexity
Linear in the distance between first and last.
Example
#include <experimental/algorithm> #include <iostream> #include <string> int main() { std::string sample{"ABCDEF"}; for (int i = 0; i != 4; ++i) { std::experimental::shuffle(sample.begin(), sample.end()); std::cout << sample << '\n'; } }
Possible output:
DACBFE CDFBAE BDCAFE BAFCED