블로그 이미지
송시혁

calendar

1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Notice

Tag

Recent Post

Recent Comment

Recent Trackback

Archive








#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
  int i;
  long seed;
  
  printf("1에서 1000 사이의 난수 5개의 생성\n");
  for( i = 0; i <= 5; i++)
  {
    printf("%7d", (rand() % 1000) + 1);
  }
  printf("\n");
  
  printf("\nRandom Number Generation Using Seed Value\n");

  
  seed = time (NULL);
  srand (seed);
  for(i = 0; i <= 5; i= i+1)
  {
    
    printf("%7d", (rand() % 1000) +1);
  }

  printf("\n");

}










이것은 로또번호 프로그램.

rand = 랜덤하게 숫자를 뽑아낸다.

srand = 랜덤으로 뽑아내되,  실행할 때마다 값이 달라니다.

srand(time NUll) 

time(NULL) =  1970년 1월 1일부터 시간을 계산하여

초로 바꾼놈이다.



#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
  int i;
  long seed;
  
  
  
  printf("\n로또 번호는 :\n");

  seed = time (NULL);
  srand (seed);
  for(i = 0; i < 6; i= i+1)
  {
    
    printf("%7d", (rand() % 45) +1);
  }

  printf("\n");




}

posted by 송시혁