Answer the question
In order to leave comments, you need to log in
Why doesn't the value in the function change?
Hello! Here is the software.
void test_random(void)
{
srand(time(NULL));
u16 value = rand()%24;
printf("value = %d\n", value);
}
void main(void)
{
int i;
for(i = 0; i < 10; i++) {
test_random();
}
}
Answer the question
In order to leave comments, you need to log in
Because time doesn't have time to change in your ten cycles, and you use it to initialize the random number generator. Can take out srand for a cycle?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question