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

后端 未结 3 459
梦毁少年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:32

    You initialize the pseudorandom generator using the current time. On most platforms the time function returns the current time in seconds. If you run this program multiple times in a single second then you will set the same seed in all executions, and get the same "random" number.

    Add e.g. a sleep 1 in the loop in the script and you will see a different result.

提交回复
热议问题