| Technical Specification | ||||
| Filesystem library(filesystem TS) | ||||
| Library fundamentals(library fundamentals TS) | ||||
| Library fundamentals 2(library fundamentals TS v2) | ||||
| Library fundamentals 3(library fundamentals TS v3) | ||||
| Extensions for parallelism(parallelism TS) | ||||
| Extensions for parallelism 2(parallelism TS v2) | ||||
| Extensions for concurrency(concurrency TS) | ||||
| Extensions for concurrency 2(concurrency TS v2) | ||||
| Concepts(concepts TS) | ||||
| Ranges(ranges TS) | ||||
| Reflection(reflection TS) | ||||
| Mathematical special functions(special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
Defined in header <experimental/algorithm> | ||
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 theper-thread random number engine as the random number generator.
Contents |
| first, last | - | the range of elements to shuffle randomly |
-RandomIt must meet the requirements ofValueSwappable andLegacyRandomAccessIterator. | ||
(none)
Linear in the distance betweenfirst andlast.
#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:
DACBFECDFBAEBDCAFEBAFCED
(until C++17)(C++11) | randomly re-orders elements in a range (function template)[edit] |