[C++]짝수를 랜덤으로 출력,홀수를 랜덤으로 출력하는 방법에 대해 질문이요
말달리자
#include iostream
#include cstdlib
#include ctime
using namespace std;
// 임의의 정수를 랜덤하게 제공하는 클래스
class Random {
public:
Random(); // 생성자. 랜덤 seed를 설정한다.
int next(); // 랜던 정수를 리턴한다.
int nextInRange(int low, int high); // low와 high 사이의 랜덤 정수를 리턴한다.
};
Random::Random() {
srand((unsigned)time(0)); // 임의의 seed를 설정하여 할 때마다 다른 랜덤 수가 나오게 한다.
}
int Random::next() {
return rand(); // 0에서 RAND_MAX 사이의 랜덤한 정수 리턴
}
int Random::nextInRange(int low, int high) {
int range=(high-low)+1;
return low + (rand() % range); // low와 high 사이의 랜덤 정수를 리턴한다.
}
--------------------------------------------------------------------------------------
랜덤클래스를 만들어서 출력하는 소스인데요
클래스 성격을 단순히 난수만 발생시키는것이 아니라
짝수,홀수를 랜덤하게 발생시킬 수 있는 클래스를 만들고 싶은데
그니까 짝수를 랜덤하게 10개, 홀수를 랜덤하게 10개 이렇게요
그런데 코드를 어떻게 짜야할지 감이 안와서요 ㅠㅠ
아시는 분 계시나요??