std::string in = "123456789";
std::vector<char> out;
std::shuffle(in.begin(), in.end(),
std::mt19937{ std::random_device{}() });
std::sample(in.begin(), in.end(), std::back_inserter(out),4,
std::mt19937{ std::random_device{}() });
const std::string answer(out.begin(), out.end());
std::cout << answer;