1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
 
class Random {
public:
    Random() { srand((unsigned)time(0)); }
    int next();
    int nextInRange(int low, int high);
};
 
int Random::next() {
    int number = rand();
    return number;
}
 
int Random::nextInRange(int low, int high) {
    int number = rand() % (high - low + 1+ low;
    return number;
}
 
int main() {
    Random r;
    cout << "-- 0에서 " << RAND_MAX << "까지의 랜덤 정수 10 개--" << endl;
    for (int i = 0; i < 10; i++) {
        int n = r.next();
        cout << n << ' ';
    }
    cout << endl << endl << "-- 2에서 " << "4 까지의랜덤 정수 10 개 --" << endl;
    for (int i = 0; i < 10; i++) {
        int n = r.nextInRange(24);
        cout << n << ' ';
    }
    cout << endl;
}
cs


+ Recent posts