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

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

    rand() will produce the same sequence of numbers for the same seed (the one you set with srand()).

    It's very likely that your loop runs too fast and all your runs end up using the same seed (i.e. time(NULL) returns same value). Hence, you see the same output.

    You can drand48() instead for producing uniformly distributed numbers. Or if you simply want to test rand(), you can just add a delay between your iterations.

提交回复
热议问题