Advertisement
angryatti

Lottery URNG Randomv2

Oct 12th, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <set>
  5. #include <random>
  6.  
  7. using namespace std;
  8.  
  9. void lotteryGen(int lotteryType, int numberCount)
  10. {
  11.  
  12.     random_device rd;
  13.     mt19937 gen(rd());
  14.     uniform_int_distribution<> dist(1, numberCount);
  15.  
  16.     set<int> lotteryNumber;
  17.  
  18.     while (lotteryNumber.size() != lotteryType)
  19.     {
  20.         int randtemp = dist(gen);
  21.  
  22.         lotteryNumber.insert(randtemp);
  23.     }
  24.  
  25.     for (auto it = lotteryNumber.begin(); it !=
  26.                                           lotteryNumber.end();
  27.          ++it)
  28.     {
  29.  
  30.         cout << ' ' << *it;
  31.     }
  32.     cout << "" << endl;
  33. }
  34.  
  35. int main()
  36. {
  37.  
  38.     int times = 0;
  39.  
  40.     int typeLottery = 0;
  41.  
  42.     cout << "Adja meg hanyas lotto (5,6,7)" << endl;
  43.     cin >> typeLottery;
  44.  
  45.     if (typeLottery != 5 && typeLottery != 6 && typeLottery != 7)
  46.     {
  47.         exit(3);
  48.     }
  49.     cout << "Adja meg hany mezot szeretne generalni:" << endl;
  50.  
  51.     cin >> times;
  52.  
  53.     for (int i = 1; i <= times; i++)
  54.     {
  55.  
  56.         switch (typeLottery)
  57.         {
  58.         case 5:
  59.             lotteryGen(5, 90);
  60.             break;
  61.         case 6:
  62.             lotteryGen(6, 45);
  63.             break;
  64.         case 7:
  65.             lotteryGen(7, 35);
  66.             break;
  67.         default:
  68.             cout << "Adja meg ujra a kivant tipust";
  69.             break;
  70.         }
  71.     }
  72.  
  73.     return 0;
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement