#include <algorithm>
#include <cassert>
#include <iostream>
#include <iterator>
#include <random>
#include <vector>
// Fisher–Yates_shuffle
std::vector<int> FisherYatesShuffle(std::size_t size, std::size_t max_size, std::mt19937& gen)
{
assert(size < max_size);
std::vector<int> res(size);
for(std::size_t i = 0; i != max_size; ++i) {
std::uniform_int_distribution<> dis(0, i);
std::size_t j = dis(gen);
if (j < res.size()) {
if (i != j) {
res[i] = res[j];
}
res[j] = 1 + i;
}
}
return res;
}
int main()
{
std::random_device rd;
std::mt19937 gen(rd());
std::vector<int> b = FisherYatesShuffle(7, 35, gen);
std::copy(b.begin(), b.end(), std::ostream_iterator<int>(std::cout, " "));
return 0;
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGNhc3NlcnQ+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGl0ZXJhdG9yPgojaW5jbHVkZSA8cmFuZG9tPgojaW5jbHVkZSA8dmVjdG9yPgoKLy8gRmlzaGVy4oCTWWF0ZXNfc2h1ZmZsZQpzdGQ6OnZlY3RvcjxpbnQ+IEZpc2hlcllhdGVzU2h1ZmZsZShzdGQ6OnNpemVfdCBzaXplLCBzdGQ6OnNpemVfdCBtYXhfc2l6ZSwgc3RkOjptdDE5OTM3JiBnZW4pCnsKICAgIGFzc2VydChzaXplIDwgbWF4X3NpemUpOwogICAgc3RkOjp2ZWN0b3I8aW50PiByZXMoc2l6ZSk7CgogICAgZm9yKHN0ZDo6c2l6ZV90IGkgPSAwOyBpICE9IG1heF9zaXplOyArK2kpIHsKICAgICAgICBzdGQ6OnVuaWZvcm1faW50X2Rpc3RyaWJ1dGlvbjw+IGRpcygwLCBpKTsKICAgICAgICBzdGQ6OnNpemVfdCBqID0gZGlzKGdlbik7CiAgICAgICAgaWYgKGogPCByZXMuc2l6ZSgpKSB7CiAgICAgICAgICAgIGlmIChpICE9IGopIHsKICAgICAgICAgICAgICAgIHJlc1tpXSA9IHJlc1tqXTsKICAgICAgICAgICAg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