Daily bit(e) of C++ | std::shuffle
Daily bit(e) of C++ ♻️57, Randomly shuffling a range of elements using std::shuffle.
When we need to shuffle elements into a random order, we can use the C++11 std::shuffle algorithm, which relies on a random engine as the source of randomness.
Any random engine can be used, but for simple use cases, the implementation-defined std::default_random_engine is typically sufficient.
The algorithm has a C++20 range version but doesn't provide a parallel version, and because random-number generation is inherently runtime, there are also no constexpr variants.