C++ 난수생성
정수 fromNum 이상, 정수 toNum 이하의 난수를 리턴한다.

#include <cstdlib>
#include <ctime>
// 난수생성 (정수 fromNum 이상, 정수 toNum 이하의 난수를 리턴)
int NumberUtil::getRandomNumber(int fromNum, int toNum) {
// 타임값으로 시드생성
int seed = (unsigned int)time(NULL);
srand(seed);
// rand() % M + N ==> N 이상 (M+N-1) 이하 난수생성
int n = fromNum;
int m = toNum – fromNum + 1;
int res = (rand() % m) + n;
return res;
}