C examples for Data Type:Random Number
Make seedrnd() function to use the current time to seed the random-number generator
#include <stdio.h> #include <stdlib.h> #include <time.h> int rnd(void); void seedrnd(void); int main()/*from w w w. ja v a2s. co m*/ { int x; seedrnd(); puts("Behold! 100 Random Numbers!"); for(x=0;x<100;x++) printf("%d\t",rnd()); return(0); } int rnd(void) { int r; r=rand(); return(r); } /* seed the random number */ void seedrnd(void) { srand((unsigned)time(NULL)); }