========================================
Example 1:
#include
// crt_rand.c / * This Program Seeds the Random-Number Generator * with the Time, The Displays 10 Random Integers. * /
#include
INT main (void) {INT I;
/ * Seed the random-number generator with current time so tria * The number we run. * / Srand ((unsigned) TIME (NULL);
/ * Display 10 NumBers. * / For (i = 0; i <10; i ) Printf ("% 6d / n", rand ());} =============== ================
Example 1: The resulting random number is the same, run in a single program, such as: for loop, each cycle is still different. Just run this program again, the same. Example 2: Produce The random number is not the same. Why? Isn't there an English help? SRAND (NULL)); is a seed to the random number, we call him a seed. Time value every time Different. So, the seed is different, so ... The random number generated is different .. On this truth. Before calling the rand, it is best to use one person SRAND (int X); That's ALL