The C language first generates a random number Seed Through the srand () function, and then calls rand () to generate a random number, because the random number generated by the C language is not a real random number, fixedAlgorithmSo if the seek is the same, the same random number is generated each time.
Question 2: according to the above method, I cannot generate random numbers. Only an equal deviation sequence with a tolerance of 3 or 4 is generated: # include <stdlib. h> # include <iostream. h> # include <conio. h> # include <time. h> void main () {for (INT I = 0; I <100000; I ++) {srand (unsigned) Time (null); cout <rand () <Endl ;}} expert's answer: yoursProgramThere is a problem. Every time you call srand before a random number is generated, the computer runs fast, so every time you use time, you get the same time (time precision is low, only 55 ms ). This is equivalent to using the same seed to generate a random sequence, so the random numbers generated are always the same. You should put srand outside the loop: srand (unsigned) Time (null); For (INT I = 0; I <100000; I ++) {// related statement}