1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
#include <random>
#include <vector>
#include <algorithm>
int main()
{
std::vector<std::size_t> /* v = {1,2,3,4,5,6,700,80,900,100},*/v1;
std::random_device rd;
std::mt19937 gen(rd());
std::discrete_distribution<> d({1,2,3,4,5,6,700,80,900,100});
for(int n = 0; n < 5; n++) {
auto index = d(gen);
while(std::find(v1.begin(), v1.end(), index) != v1.end()) {
index = d(gen);
}
v1.push_back(index);
}
/* std::cout << "\nv:\n";
for(const auto& s : v)
std::cout << s << " ";
std::cout << "\n";*/
std::cout << "v1:\n";
for(const auto& s : v1)
std::cout << s << " ";
std::cout << "\n";
}
|