SHARE
TWEET

loto.cpp

a guest Dec 6th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ConsoleApplication2.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5. #include <vector>
  6. #include <random>
  7.  
  8. using std::vector;
  9. using std::cout;
  10. using std::random_device;
  11. using std::mt19937;
  12. using std::uniform_int_distribution;
  13. using std::endl;
  14.  
  15. int main()
  16. {
  17.  
  18.     // объявляем костанты и переменные
  19.     const int number_of_barrels = 90;
  20.     const int number_of_random_numbers_to_generate = 5;
  21.  
  22.     const int range_from = 0;
  23.     const int range_to = number_of_barrels;
  24.  
  25.     random_device rand_dev;
  26.     mt19937 generator(rand_dev());
  27.  
  28.     vector<int> barrels;
  29.  
  30.     cout << "Filling vector." << endl;
  31.     for(int i = 0; i < number_of_barrels; i++) {
  32.         barrels.push_back(i+1);
  33.     }
  34.  
  35.  
  36.     cout << "Getting 5 random numbers from the vector and showing it on the screen:" << endl;
  37.     for(int i = 0; i < number_of_random_numbers_to_generate; i++) {
  38.         uniform_int_distribution<int> distr(range_from, range_to - i);
  39.         int randomNumber = distr(generator); // генерируем рандомное число
  40.         int numberAt = barrels.at(randomNumber); // читаем число из вектора и иницализируем переменную numberAt этим числом
  41.         barrels.erase(std::cbegin(barrels) + randomNumber); // удаляем это число из вектора
  42.         cout << numberAt << " "; // выводим это число на экран.
  43.     }
  44.  
  45. }
  46.  
  47. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  48. // Debug program: F5 or Debug > Start Debugging menu
  49.  
  50. // Tips for Getting Started:
  51. //   1. Use the Solution Explorer window to add/manage files
  52. //   2. Use the Team Explorer window to connect to source control
  53. //   3. Use the Output window to see build output and other messages
  54. //   4. Use the Error List window to view errors
  55. //   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
  56. //   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top