#include <time.h>
Srand
The Srand function is the initialization function of the random number generator. Prototype: void Srand (unsigned int seed);
Srand and Rand () work together to produce a sequence of pseudo-random numbers. The RAND function requires a system-supplied seed to generate a sequence of pseudo-random numbers before generating a random number, and Rand produces a series of random numbers based on the value of the seed. If the seed provided by the system does not change, the sequence of pseudo-random numbers generated by each call to the RAND function is the same. Srand (unsigned seed) alters the seed value provided by the system through the parameter seed, which allows the sequence of pseudo-random numbers generated by each call to the RAND function to be different, thus achieving a true "random" meaning. System time can often be used to change the system's seed value, which is srand, which can provide different seed values for the RAND function, resulting in a different sequence of random numbers
The following program is the number of guesses, randomly generated 0-100, greater than 80 win, other losses.
1#include <stdio.h>2#include <stdlib.h>3#include <time.h>4 /*the reason for this header file is that you need to use the time data type time_t*/5 6 Main ()7 {8time_t ts;/*Time Variable*/9 TenSrand ((unsignedint) time (&ts));/*time is a function that gets the times saved results in TS*/ One A intnum = rand ()% -+1;/*get random number*/ - -printf"num=%d\n", num); the -num > the? printf"win"): printf ("lose"); -}
#include <time.h>