std::experimental:: shuffle
From ko.cppreference.net
<
cpp
|
experimental
|
헤더 파일에 정의됨
<experimental/algorithm>
|
||
|
template
<
class
RandomIt
>
void shuffle ( RandomIt first, RandomIt last ) ; |
(라이브러리 fundamentals TS v2) | |
주어진 범위
[
first
,
last
)
내의 요소들을 재정렬하여, 각 가능한 순열이 동일한 확률로 나타나도록 합니다. 이때
스레드별 난수 엔진
을 난수 생성기로 사용합니다.
목차매개변수
반환값(없음) 복잡도first 와 last 사이의 거리에 선형적으로 비례합니다. 예제
이 코드 실행
#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'; } } 가능한 출력: DACBFE CDFBAE BDCAFE BAFCED 참고 항목
| |||||||||