开发者

srandom( time( NULL ) )

May I know the meaning or开发者_如何学Python even how to read this:

srandom( time( NULL ) )?


NULL

A null pointer. Zero. Points to nothing.

time(NULL)

The time function 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.

srandom(time(NULL))

The s means "seed". srandom means "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.

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.


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


srandom is a function that initializes the random number generator.

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

This is read, "srandom of time of null".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜