daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Nov 17th, 2018 60 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  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. }
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