且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么rand()在这个for循环中使用srand(time(null))返回相同的值?

更新时间:2021-08-28 23:02:50

因为你每次都使用相同的值播种– time 只有二级精度,我相信您的计算机可以在一秒钟内处理这六个循环迭代。 ; - ]

Because you're seeding with the same value each time – time only has second-level precision, and I'm quite sure your computer can process those six loop iterations within one second. ;-]

在程序开始时种子

Seed once, at the beginning of the program.