2012년 10월 19일 금요일

[C++] 난수 만들기

1. 소스 내용
#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

int randNum(){

 srand(time(NULL));

 for(int x = 0 ; x <= 10 ; x++){
  cout << rand() % 10 +1 << endl;
 }
}

int main() {

 randNum();

 return 0;
}

2. 실행 결과
   : 실행 할 때 마다 결과가 달라진다.
6
9
10
10
1
7
5
7
9
8
5

댓글 없음 :

댓글 쓰기