Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <iomanip>
- using namespace std;
- template<typename Integer>
- struct RandInteger {
- static Integer generate(Integer a, Integer b) {
- if (a > b) swap(a, b);
- const uniform_int_distribution<Integer> uid(a, b);
- random_device rd;
- return uid(rd);
- }
- };
- template<typename Real>
- struct RandReal {
- static Real generate(Real a, Real b) {
- if (a > b) swap(a, b);
- const uniform_real_distribution<Real> uid(a, b);
- random_device rd;
- return uid(rd);
- }
- };
- int main() {
- const auto n = 10U;
- for (auto i = n; i; --i) cout << setw(4) << RandInteger<short>::generate(-48, 59) << '\n';
- cout.put('\n');
- for (auto i = n; i; --i) cout << setw(11) << fixed << setprecision (6) << RandReal<float>::generate(-48, 59) << '\n';
- cout.put('\n');
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement