Recently I had been stuck on a question. I have a C code file (call "test.c" and output is "test.out") like below and just a simple output of random number:
int main()
{
srand(time(NULL));
double r = (double)rand() / (double)RAND_MAX;
printf("%f\n", r);
return 0;
}
and now I use shell scripts to run "test.out" 5 times in Linux, the code below:
for i in 1 2 3 4 5
do
test.out
done
but the result show like below
0.840188
0.840188
0.840188
0.840188
0.840188
It shows the same random number...
Can anyone have any suggestion?
Thanks a million!
Aucun commentaire:
Enregistrer un commentaire