mercredi 19 décembre 2018

Printing pseudo-random number with calling function ? [duplicate]

When I compiled this code, I encountered the same numbers which are "num" times.But I want to take different random numbers.How can I fix it?

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int create_random(int num);


int main() 
{ 
  int i=0,num=0;
  printf("How many random number ? ");//Request from user..
  scanf("%d",&num);
  for(i=0 ; i<num ; ++i)
{
    printf("%d\n",create_random(i));    
}

return 0; 
}

int create_random(int a)
{

  a=0;
  srand(time(NULL));
  a=rand()%100;

return a;
} 




Aucun commentaire:

Enregistrer un commentaire