C语言 随机(时间(NULL))

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2311014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 04:34:52  来源:igfitidea点击:

srandom( time( NULL ) )

crandom

提问by joseph fernandez

May I know the meaning or even how to read this:

我可以知道这个意思,甚至如何阅读:

srandom( time( NULL ) )?

回答by kennytm

NULL

A null pointer. Zero. Points to nothing.

一个空指针。零。指向无。

time(NULL)

The timefunction returns the current timestamp as an integer. It accepts an input argument. If the argument is not null, the current time is stored in it.

time函数以整数形式返回当前时间戳。它接受一个输入参数。如果参数不为空,则将当前时间存储在其中。

srandom(time(NULL))

The smeans "seed". srandommeans "seed the random number generator". It takes an integer as input, reset the PRNG's internal state derived by the input to generate a sequence of random numbers according to it. The seed is sometimes used to ensure 2 sequences of random numbers are the same, to reproduce an equivalent testing condition.

s装置的“种子”。srandom意思是“种子随机数生成器”。它以一个整数作为输入,重置由输入导出的PRNG的内部状态,根据它生成一个随机数序列。种子有时用于确保 2 个随机数序列相同,以重现等效的测试条件。

In general, you just put some always changing value there to avoid having the same sequence every time the program is started. The current timestamp is a good value, so time(NULL)is used as the input.

通常,您只需在其中放置一些始终更改的值,以避免每次启动程序时都具有相同的序列。当前时间戳是一个很好的值,因此time(NULL)用作输入。

回答by Mad Fish

The meaning is to initialize the random seed with the current time. time(NULL) returns the current time. srandom() initializes random seed.

意思是用当前时间初始化随机种子。time(NULL) 返回当前时间。srandom() 初始化随机种子。

回答by SLaks

srandomis a function that initializes the random number generator.

srandom是一个初始化随机数生成器的函数。

It takes a seed value, which in this code is time(NULL), which is the current time.

它需要一个种子值,在此代码中为time(NULL),即当前时间。

This is read, "srandom oftime ofnull".

这是读,“srandom时间空”。