The function commonly used to go to the random number is rand ()(in the Stdlib.h header file, different compilers may be different), but actually when using this function it is found that each program runs the same number of times, what is the reason? In fact, it is incorrect to use.
A random number is actually a set of values calculated from the initial data (called a seed) based on a recursive formula, and when the sequence is long enough, this set of values approximates the uniform distribution. In use, if you do not change the initial data each time the calculated number is the same, that is, pseudo-random number. For example:
The program runs for each of these three numbers. That is, pseudo-random number
How can you do this if you want to become a real random number that requires a different seed (that is, initial data) each time you run it? The current use of system time as a seed, because the system time is changing. This requires another function Srand ()(also in the Stdlib.h header file, Different compilers may be different), adding a time.h header file with the current time value as the seed of the srand, which guarantees that a different random number can be taken each time it is run. A change to the previous program would enable the actual random number to be taken.
This will result in a different run every time.
If you want to limit the range rand ()%100, the range is 0-99.
C-language take random number