Rahul Chandok said:
I am including a small program for calculating the random number.
#include <stdio.h>
#include<sys/types.h>
This isn't a standard header, but you don't seem to be using anything
from it anyway.
There's no such header. I presume you mean <time.h>.
If you're going to post code, please at least try compiling it first.
#include <stdlib.h>
int randomgen();
int main()
Ok, but "int main(void)" is better.
{
time_t seed;
int i = 0; randomnumber = 0;
There's no need to initialize either variable; both have values
assigned to them before they're used.
seed = time(NULL);
srand(seed);
What is the purpose of the intermediate variable "seed"? You could
just write "srand(time(NULL));".
for ( i = 0; 1 < 1000; i++)
{
randomnumber = randomgen();
printf("Random Number generated is %d\n",randomnumber);
}
}
int randomgen()
{
return rand();
}
What is the purpose of this function? Why not just call rand()
directly?