函数srand(时间(NULL)) [英] srand(time(NULL))
问题描述
关于C95:
是srand(time(NULL));播种rand()的有效解决方案,还是
还有更好的方法吗?
Regarding C95:
Is srand(time(NULL)); an effective solution for seeding rand(), or is
there any better approach?
推荐答案
Ioannis Vranos写道:
Ioannis Vranos wrote:
关于C95:
是srand(time(NULL));播种rand()的有效解决方案,还是
还有更好的方法吗?
Regarding C95:
Is srand(time(NULL)); an effective solution for seeding rand(), or is
there any better approach?
C FAQ中第13节的这个区域有一些讨论
( http://www.c-faq.com)。尝试问题13.17
There''s some discussion in this area in section 13 of the C FAQ
(http://www.c-faq.com). Try Question 13.17
Ioannis Vranos写道:
Ioannis Vranos wrote:
关于C95:
srand(time(NULL));播种rand()的有效解决方案,还是
还有更好的方法吗?
Regarding C95:
Is srand(time(NULL)); an effective solution for seeding rand(), or is
there any better approach?
除了我之前的回复,Google还为
播种随机数生成器提供了大量点击,其中许多看起来很像很有帮助。
In addition to my previous reply, Google gives loads of hits for
"seeding a random number generator", many of which look helpful.
Ioannis Vranos< iv ***** @ nospam.no.spamfreemail.grwrote:
Ioannis Vranos <iv*****@nospam.no.spamfreemail.grwrote:
是srand(time(NULL));播种rand()的有效解决方案,
Is srand(time(NULL)); an effective solution for seeding rand(),
除非你的time_t是浮点类型且当前时间比UINT_MAX大
(不太可能,特别是第一部分);
,只要你不是每次都打电话不止一次_t tick;
和你的兰特一样长( )至少是半合理的质量(即,
连续的种子不会导致类似的系列),它没关系。
理查德
Unless your time_t is a floating point type and the current time is
larger than UINT_MAX (not likely, in particular the first part);
as long as you don''t call it more than once every time_t tick;
and as long as your rand() is at least of semi-reasonable quality (i.e.,
successive seeds don''t lead to similar series), it''s fine.
Richard
这篇关于函数srand(时间(NULL))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!