Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::shuffle

      From cppreference.com
      <cpp‎ |experimental
       
       
       
       
      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[firstlast) 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

      [edit]Parameters

      first, last - the range of elements to shuffle randomly
      -
      RandomIt must meet the requirements ofValueSwappable andLegacyRandomAccessIterator.

      [edit]Return value

      (none)

      [edit]Complexity

      Linear in the distance betweenfirst andlast.

      [edit]Example

      Run this code
      #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

      [edit]See also

      (until C++17)(C++11)
      randomly re-orders elements in a range
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/experimental/shuffle&oldid=155811"

      [8]ページ先頭

      ©2009-2026 Movatter.jp