A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/algorithm/../../cpp/../cpp/header/../experimental/shuffle.html below:

std::experimental::shuffle - cppreference.com

template< class RandomIt >
void shuffle( RandomIt first, RandomIt last );

(library fundamentals TS v2)

Reorders the elements in the given range [firstlast) 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.

[edit] Parameters [edit] Return value

(none)

[edit] Complexity

Linear in the distance between first and last.

[edit] 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
[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4