about srandom( time( NULL ))
来源:互联网 发布:linux 退出cat命令 编辑:程序博客网 时间:2024/05/07 00:09
NULL
A null pointer. Zero. Points tonothing.
time(NULL)
The time function returns the currenttimestamp as an integer. It
accepts an input argument. If theargument is not null, the current time
is stored in it.
srandom(time(NULL))
The s means "seed". srandom means "seedthe random number generator". It
takes an integer as input, reset thePRNG's internal state derived by
the input to generate a sequence ofrandom numbers according to it. The
seed is sometimes used to ensure 2sequences of random numbers are the
same, to reproduce an equivalent testingcondition.
In general, you just put some alwayschanging value there to avoid
having the same sequence every time theprogram is started. The current
timestamp is a good value, so time(NULL)is used as the input.
Name
random,
Synopsis
#include <stdlib.h>long int random(void);void srandom(unsigned int seed);char *initstate(unsigned int seed, char *state, size_t n);char *setstate(char *state);
FeatureTest Macro Requirements for glibc(see - random(),
srandom(), initstate(), setstate(): - _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >=500 || _XOPEN_SOURCE &&_XOPEN_SOURCE_EXTENDED
Description
The
The
The
The
Return Value
The
Errors
- EINVAL
A state array of less than 8 bytes was specifiedtoinitstate().
Conforming To
4.3BSD, POSIX.1-2001.
Notes
Current "optimal" values for the size of the statearray
This function should not be used in cases where multiple threadsuse
Random-number generation is a complextopic.
For a more theoretical discussion which also covers many practicalissues in depth, see Chapter 3 (Random Numbers) in Donald E.Knuth's
- about srandom( time( NULL ))
-  
-
- Time and Time Again
- Reading time : Cognitive Radio :…
- Know more about checkpoint
- about googleMap and googleEarth
- About Trace Files
- about using gnuplot
- Time Division Multiple Access
- MYSQL YEAR TIME DATE
- OPP time out 问题
- strftime time server
- hdoj acm 1008
- HDOJ 1984 Mispelling4
- How to get Time Separator in Jav…
- em的错误 <转载>
- 集线器 交换机 路由器 网桥 …
- 骑士信条
- Run Chinese CAJviewer by wine
- 一个大牛工程师的一些建议
- Power Measurement Units
- 一次“ERROR: OALL8 is in an inconsistent state”处理
- about srandom( time( NULL ))
- Ubuntu下deb与rpm包的安装方法
- Makefiles by example
- Description of FIR Filters
- c++ vector
- 一个学通信的人写的情书
- 程序员
- Best Readings in Cognitive Radio
- 简单工厂模式