srand(time(0))和随机数生成 [英] srand(time(0)) and random number generation
本文介绍了srand(time(0))和随机数生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
srand(time(0))
但是,你能解释一下它到底是什么?
But, can you explain what it exactly does?
感谢。
推荐答案
srand()
给随机函数一个新的种子,一个起始点(通常是通过取前一个数字(或种子)计算随机数,然后对该数字进行很多操作以生成下一个)。
srand()
gives the random function a new seed, a starting point (usually random numbers are calculated by taking the previous number (or the seed) and then do many operations on that number to generate the next).
time(0)
给出了自Unix纪元以来的时间,以秒为单位,这是一个相当不错的不可预测种子将只有一次,除非你在同一秒钟内多次启动你的程序)。
time(0)
gives the time in seconds since the Unix epoch, which is a pretty good "unpredictable" seed (you're guaranteed your seed will be the same only once, unless you start your program multiple times within the same second).
这篇关于srand(time(0))和随机数生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文