If I don't specify srand(), what seed does rand() use?

前端 未结 5 1551
借酒劲吻你
借酒劲吻你 2020-12-11 18:44

Here is the code:

#include 
#include 
#include 

int main(void)
{
    int r;
    int i;
    for (i = 0; i < 1         


        
5条回答
  •  遥遥无期
    2020-12-11 19:15

    The C standard actually stipulates the behaviour documented in the other answers:

    ISO/IEC 9899:2011 §7.22.2.2 The srand function

    ¶2 [...] If rand is called before any calls to srand have been made, the same sequence shall be generated as when srand is first called with a seed value of 1.

提交回复
热议问题