I've had this problem a long time ago, and today I stepped on the pit ...
If you want to generate random numbers in the C language, you need to call RAND ()
Description
The C library function int rand(void) returns a pseudo-random number in the range of 0 to RAND_MAX. RAND_MAX is a constant whose default value may vary between implementations but it is granted to be at least 32767.
#include <stdio.h>#include <stdlib.h>int main(){ int0; for05;temp++) { printf("%d\t",rand()); } printf("\n"); return0;}
I am (‵o′) convex every time the same result, you told me you are random number? I X
Here you need to initialize ... It is best to use the current time to seed and then "feed" the Srand () function to initialize the rand (). Each time the program is called, because the time is different, the seed is different, randomly can always get different random numbers.
#include <stdio.h>#include <stdlib.h>int main(){ int0; srand(time(NULL)); for05;temp++) { printf("%d\t",rand()); } printf("\n"); return0;}
Some time ago also see DSAA How to write a rand (), and was indefinitely shelved ...
Problems encountered in generating random numbers for C programs