std::experimental::shuffle(3)
π NAME π
std::experimental::shuffle β std::experimental::shuffle. Thatβs literally the name, bestie. Iconic behavior, no notes. π
okay so this is the std::experimental::shuffle(3) page from the C++ Standard Libary manual β yes, βLibary,β thatβs how itβs spelled in the header, Iβm not fixing it π«Ά.
β¨ Synopsis β¨
Defined in header <experimental/algorithm>, and the vibe is library fundamentals TS v2:
Defined in header <experimental/algorithm>
template< class RandomIt > (library fundamentals
TS v2)
void shuffle( RandomIt first, RandomIt last );
The way this works: it reorders the elements in the given range [first, last) so that each possible permutation of those elements has equal probability of appearance, using the per-thread random number engine as the random number generator. Thatβs the whole slay. πΈ
π Parameters π
first,lastβ the range of elements to shuffle randomly.RandomItβ must meet the requirements ofValueSwappableandLegacyRandomAccessIterator.
π«Ά Return value π«Ά
(none) β thatβs the whole return value section, bestie. Nothing comes back. π
π₯ Complexity π₯
Linear in the distance between first and last. Lowkey efficient, highkey iconic. β¨
π Example π
// Run this code β yes bestie, run it, live a little π
#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
π See also π
random_shuffleβ randomly re-orders elements in a range; function template; until C++17.shuffleβ randomly re-orders elements in a range; function template; C++11.
later bestie π β source: http://cppreference.com; version/date: 2024.06.10. mwah, periodt. π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms