Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <iomanip>
  4. using namespace std;
  5. template<typename Integer>
  6. struct RandInteger {
  7.     static Integer generate(Integer a, Integer b) {
  8.         if (a > b) swap(a, b);
  9.         const uniform_int_distribution<Integer> uid(a, b);
  10.         random_device rd;
  11.         return uid(rd);
  12.     }
  13. };
  14. template<typename Real>
  15. struct RandReal {
  16.     static Real generate(Real a, Real b) {
  17.         if (a > b) swap(a, b);
  18.         const uniform_real_distribution<Real> uid(a, b);
  19.         random_device rd;
  20.         return uid(rd);
  21.     }
  22. };
  23. int main() {
  24.     const auto n = 10U;
  25.     for (auto i = n; i; --i) cout << setw(4) << RandInteger<short>::generate(-48, 59) << '\n';
  26.     cout.put('\n');
  27.     for (auto i = n; i; --i) cout << setw(11) << fixed << setprecision (6) << RandReal<float>::generate(-48, 59) << '\n';
  28.     cout.put('\n');
  29.     system("pause");
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement