The std::sample algorithm (C++17) is a stable (maintains relative order of elements) sampling algorithm that randomly copies the specified number of elements from the source range into the destination range (output iterator).
Compiler Explorer link: https://compiler-explorer.com/z/EWazzMbns