Guest User

Untitled

a guest
Jul 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <ctime>
  4.  
  5.  
  6. using namespace std;
  7. int main()
  8. {
  9. tryAgain:
  10. srand(time(NULL));
  11. setlocale(LC_ALL, "ru");
  12. bool alreadyThere;
  13. int randNumber, quantity, selection;
  14. int fourNull = 0000;
  15.  
  16.  
  17.  
  18. cout << "Выберите тип генерации" << endl
  19. << "1.Упорядоченный" << endl
  20. << "2.Рандомный" << endl;
  21. cin >> selection;
  22.  
  23. switch (selection)
  24. {
  25. case 1:
  26. cout << "Выберите количество генерируемых номеров" << endl;
  27. cin >> quantity;
  28. alreadyThere = false;
  29. while (fourNull <= quantity)
  30. {
  31. fourNull++;
  32. cout << "+7910000" << setw(4) << setfill('0') << fourNull << "tt";
  33.  
  34. }
  35. goto tryAgain;
  36. break;
  37.  
  38. case 2:
  39. cout << "Выберите количество генерируемых номеров" << endl;
  40. cin >> quantity;
  41. for (int i = 0; i <= quantity; i++)
  42. {
  43.  
  44.  
  45.  
  46. randNumber = rand() %9999 + fourNull;
  47. cout << "+7910000" << setw(4) << setfill('0') << randNumber << "tt";
  48.  
  49.  
  50.  
  51. }
  52. goto tryAgain;
  53. break;
  54.  
  55. default:
  56. goto tryAgain;
  57. break;
  58.  
  59. }
  60. system("pause");
  61. return 0;
  62. }
  63.  
  64. #include <iostream>
  65. #include <vector>
  66. #include <algorithm>
  67. #include <ctime>
  68.  
  69. using namespace std;
  70.  
  71. int main(){
  72. vector<int> x(10); // вектор из десяти элементов
  73.  
  74. for (int i = 0; i < 10; i++){
  75. x[i] = i; // инициализация диапозоном от 0 до 10 (здесь вы можете указать свой диапозон)
  76. }
  77.  
  78. srand(unsigned(time(0)));
  79. random_shuffle(x.begin(), x.end()); // перемешиваеаем
  80.  
  81. for (int i = 0; i < 10; i++){
  82. cout << x[i] << endl; // вывод
  83. }
  84.  
  85. return 0;
  86. }
  87.  
  88. void unique_random_numbers(int min, int max, int amt)
  89. {
  90. std::map<int, int> m;
  91. int r{}, count{}, range = max - min + 1;
  92. while (count < amt) {
  93. r = min + rand()% range;
  94. m[r]++;
  95. if(m[r] == 1) {
  96. ++count;
  97. cout << r <<endl;
  98. }
  99. }
  100. }
Add Comment
Please, Sign In to add comment