#include <iostream>
#include <cstring>
#include<stdlib.h>
#include<time.h>
#define BUFFER_SIZE 2000;
using namespace std;
class SelectableRandom {
int first, last,EorO;
int radnum;
int randomlist[10];
public:
SelectableRandom();
SelectableRandom(int x, int y,int z);
void show();
void random();
};
SelectableRandom::SelectableRandom() {
}
SelectableRandom::SelectableRandom(int x, int y,int z) {
first = x;
last = y;
EorO = z;
}
void SelectableRandom::random() {
int t = 0,i=0;
if (EorO == 0) {//짝
while (i<10)
{
radnum = rand() % (last - first) + first;
if (radnum % 2 == 0) {
randomlist[i] = radnum;
i++;
}
}
}
else if (EorO == 1) {
while (i<10)
{
radnum = rand() % (last - first) + first;
if (radnum % 2 == 1) {
randomlist[i] = radnum;
i++;
}
}
}
}
void SelectableRandom::show() {
if (EorO == 0) {
cout << "== " << first << "에서 " << last << "까지의 짝수 랜덤정수 10개 ==" << endl;
for (int i = 0; i < 10; i++) {
cout << randomlist[i] << " ";
}
cout << endl;
}
else if (EorO == 1) {
cout << "== " << first << "에서 " << last << "까지의 홀수 랜덤정수 10개 ==" << endl;
for (int i = 0; i < 10; i++) {
cout << randomlist[i] << " ";
}
cout << endl;
}
}
int main() {
srand(time(NULL));
SelectableRandom java(0, 32767,0);
java.random();
java.show();
cout << endl;
SelectableRandom java1(2, 9,1);
java1.random();
java1.show();
}