개발관련/C언어

srand함수

guuuuuuu 2014. 7. 22. 15:07

#include <stdio.h>

 #include <stdlib.h>

 #include <time.h>  // time함수를 사용하기 위해서 선언

 

 int main()

 {

     int nNum = 1;

      // 항상 다른 seed값을 넣어주기 위해 time함수를 인자로 넣어준다.

     srand((unsigned int)time(NULL));

     for(int nCount = 0; nCount < 3; ++nCount)

    {

           int nRandom = rand() % 100;

         printf("[%d] %d\n", nNum, nRandom);

         nNum++;

     }

     return 0;

 }