Run rand() in C language and loop with Shell Scripts

后端 未结 3 455
梦毁少年i
梦毁少年i 2020-12-12 07:52

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()
{
           


        
3条回答
  •  情深已故
    2020-12-12 08:42

    for i in 1 2 3 4 5
    do
        test.out
    done
    

    You execute the program 5 times in the same second, and since you are using system time in seconds as seed for your rand() function, naturally, you will get the same results. If you wait a second (or longer then a second) between executions, you will get different values.

提交回复
热议问题