更新时间:2023-02-06 08:46:29
srand ( time(NULL) );
用于植入伪随机数生成器. time()
的粒度为1秒,如果您每次调用roll_a_dice()
函数时都为PNRG设置种子,那么对于在粒度周期内进行的所有调用,rand()
最终将返回相同的 random 数字.
srand ( time(NULL) );
is used to seed the pseudo-random number generator. time()
having a granularity of 1 second, if you seed the PNRG every time you call the roll_a_dice()
function, for all the calls made within the granularity period, rand()
will end up returning the same random number.
将srand ( time(NULL) );
从roll_a_dice()
函数中移出,仅在main()
中调用一次.
Move the srand ( time(NULL) );
out of the roll_a_dice()
function, call that only once in main()
.