srand(time(0));是什么意思呀

g_yxh 2002-07-11 10:13:40
在银行柜台与客户的算法里有这么一句,是什么意思?
...全文
1869 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
freezingfire 2002-07-11
  • 打赏
  • 举报
回复
计算机没有办法产生真正的随机数的,是用算法模拟,所以你只调用rand,每次出来的东西是一样的。设置一个种子后,根据种子的不同,就可以产生不同的数了。而怎么保证种子的不同呢?最简单的办法当然是用永远在向前的时间。
liushmh 2002-07-11
  • 打赏
  • 举报
回复
用 时间作为一个随机种子数 以便获得一个随机数
HelloThis 2002-07-11
  • 打赏
  • 举报
回复
就是给这个算法一个启动种子,也就是算法的随机种子数,有这个数以后才可以产生随机数,
用1970.1.1至今的秒数,初始化随机数种子。

接着要用
rand();
wenliang_d 2002-07-11
  • 打赏
  • 举报
回复
用1970.1.1至今的秒数,初始化随机数种子。
kingfire 2002-07-11
  • 打赏
  • 举报
回复
srand(time(0));是什么意思呀???
-----------------------------------
int k=rand();
rand()就是用来产生一个随机数的函数,其实这个随机数并不是一个生活中的真正意义上的随机数,它是靠一个算法运算出来的!
srand(int);就是给这个算法一个启动种子,也就是算法的随机种子数,有这个数以后才可以产生随机数!!!
born20c 2002-07-11
  • 打赏
  • 举报
回复
rcmcs@ctihf:/ora2/rcmcs/tmp > man srand
重新格式化页 请等待... 完成

C Library Functions rand(3C)

NAME
rand, srand, rand_r - simple random-number generator

SYNOPSIS
#include <stdlib.h>

int rand(void);

void srand(unsigned int seed);

int rand_r(unsigned int *seed);

DESCRIPTION
The rand() function uses a multiplicative congruential
random-number generator with period 2**32 that returns suc-
cessive pseudo-random numbers in the range of 0 to RAND_MAX
(defined in <stdlib.h>).

The srand() function uses the argument seed as a seed for a
new sequence of pseudo-random numbers to be returned by sub-
sequent calls to rand(). If srand() is then called with the
same seed value, the sequence of pseudo-random numbers will
be repeated. If rand() is called before any calls to
srand() have been made, the same sequence will be generated
as when srand() is first called with a seed value of 1.

The rand_r() function has the same functionality as rand()
except that a pointer to a seed seed must be supplied by
the caller. The seed to be supplied is not the same seed as
in srand().

USAGE
The spectral....

..................................................


rcmcs@ctihf:/ora2/rcmcs/tmp > man time
重新格式化页 请等待... 完成

User Commands time(1)

NAME
time - time a simple command

SYNOPSIS
time [ -p ] utility [ argument. .. ]

DESCRIPTION
The time utility invokes utility operand with argument, and
writes a message to standard error that lists timing statis-
tics for utility. The message includes the following infor-
mation:

o The elapsed (real) time between invocation of utility
and its termination.

o The User CPU time, equivalent to the sum of the
tms_utime and tms_cutime fields returned by the
times(2) function for the process in which utility is
executed.

o The System CPU time, equivalent to the sum of the
tms_stime and tms_cstime fields returned by the
times() function for the process in which utility is
executed.

When time is used as part of a pipeline, the times reported
are unspecified, except when it is the sole command within a
grouping command in that pipeline. For example, the commands
on the left are unspecified; those on the right report on
utilities a and c, respectively.

time a | b | c { time a } | b | c
a | b | time c a | b | (time c)

OPTIONS
The following option is supported:

-p Write the timing output to standard error in the
following format:

--还有--(28%)

70,023

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧