Advertisement
Taraxacum

Unique random number

Oct 15th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <random>
  4.  
  5. using namespace std;
  6.  
  7. int main(int argc, char const *argv[])
  8. {
  9.     const int MIN = 1;
  10.     const int MAX = 100;
  11.     const int COUNT = 10;
  12.  
  13.     random_device rd;
  14.     uniform_int_distribution<int> dist(MIN, MAX);
  15.  
  16.     set<int> random_pool;
  17.     while (random_pool.size() < COUNT)
  18.     {
  19.         random_pool.insert(dist(rd));
  20.     }
  21.  
  22.     for (int r : random_pool)
  23.     {
  24.         cout << r << '\t';
  25.     }
  26.     cout << endl;
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement