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

后端 未结 7 2098
广开言路
广开言路 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:29

    The srand() function uses the argument as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls to rand(). If srand() is then called with the same seed value, the sequence of pseudo-random numbers shall be repeated. If rand() is called before any calls to srand() are made, the same sequence shall be generated as when srand() is first called with a seed value of 1.

    Maybe useful: http://pubs.opengroup.org/onlinepubs/009695399/functions/rand.html

    0 讨论(0)
提交回复
热议问题