how do we use the function randomize() to initialize randomization process?
functions
Collapse
X
-
Originally posted by molatelohow do we use the function randomize() to initialize randomization process?
Code:/* RAND.C: This program seeds the random-number generator * with the time, then displays 10 random integers. */ #include <stdlib.h> #include <stdio.h> #include <time.h> int main( void ) { int i; /* Seed the random-number generator with current time so that * the numbers will be different every time we run. */ srand( (unsigned)time( NULL ) ); /* Display 10 numbers. */ for( i = 0; i < 10;i++ ) printf( " %6d\n", rand() ); return 0; }
Comment
-
Originally posted by willakawillthis is from the help file in vc++
Code:/* RAND.C: This program seeds the random-number generator * with the time, then displays 10 random integers. */ #include <stdlib.h> #include <stdio.h> #include <time.h> int main( void ) { int i; /* Seed the random-number generator with current time so that * the numbers will be different every time we run. */ srand( (unsigned)time( NULL ) ); /* Display 10 numbers. */ for( i = 0; i < 10;i++ ) printf( " %6d\n", rand() ); return 0; }
Comment
-
Originally posted by molateloOk thanks, so why do you use function rand() in printf statementComment
-
Originally posted by willakawillIt is returning a random number. In this case the number is printed to the screen just for demonstration purposes. With code snippets like this you should copy them to your ide and compile them to see how it works. That is how I learn this stuff :)Comment
-
Comment