rand with seed does not return random if function looped

前端 未结 5 922
滥情空心
滥情空心 2020-12-17 21:19

I wrote this C code below, when I loop, it returns a random number. How can I achieve the 5 different random values if myrand() is executed?

#include 

        
5条回答
  •  抹茶落季
    2020-12-17 21:48

    Try this:

    #include 
    #include 
    int main(void) {
        for (int i = 0; i < 10; i++) {
            printf("%ld\n", (long)time(NULL));
        }
    }
    

    My "guess" is that 10 equal values will be printed :)

提交回复
热议问题