+ 1
Why each time I run this code it's the same result using rand() function?
3 Respuestas
+ 3
You need to set a seed first. Otherwise the random number generator will start from the same value.
https://www.tutorialspoint.com/c_standard_library/c_function_srand.htm
+ 7
Use time.h header and srand to get random values in everytime.
+ 2
#include <stdio.h>
#include <time.h>
int main() {int b;
srand(time(NULL));
for(int i=0;i<10;i++){
b= rand()%5;
printf ("%d\n",b);
};
return 0;
}