What‘s the difference between srand(1) and srand(0)

后端 未结 7 2193
广开言路
广开言路 2020-12-30 02:23

I just found out the hard way that srand(1) resets the PRNG of C(++) to the state before any call to srand (as defined in the reference). However,

7条回答
  •  鱼传尺愫
    2020-12-30 03:08

    When reading manual pages, they all state that "If no seed value is provided, the rand() function is automatically seeded with a value of 1." This is probably why the reference page you link to states that seeding with 1 resets the state.

    That the same result happens for seeding with both 0 and 1 is most likely implementation dependant, and should not be counted on happening on all platforms.

提交回复
热议问题