📄 subject_65610.htm
字号:
<p>
序号:65610 发表者:everfly 发表日期:2003-12-18 15:53:35
<br>主题:请教关于rand()的问题
<br>内容:我写了一个函数,实现产生随机数,用srand()和rand()%50,怎么每次执行产生的随机数是一样的.这是什么原因呢????
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:xiongli 回复日期:2003-12-18 15:58:28
<br>内容:srand每次撒的种子如果都是一样就会这样<BR>你可以用当前时间作为种子,这样就不一样了
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:everfly 回复日期:2003-12-18 16:03:42
<br>内容:xiongli大侠我该怎么做呢?<BR>比如说srand(5000)是不是以5000为种子,每次产生的数据是一样的呀!假如我换成别的变动的东西做种子才可以生成不同的数据。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:林建华 回复日期:2003-12-18 16:17:19
<br>内容:#include <stdlib.h><BR>#include <stdio.h><BR>#include <time.h><BR><BR>void main( void )<BR>{<BR> int i;<BR><BR> /* Seed the random-number generator with current time so that<BR> * the numbers will be different every time we run.<BR> */<BR> srand( (unsigned)time( NULL ) );<BR><BR> /* Display 10 numbers. */<BR> for( i = 0; i < 10;i++ )<BR> printf( " %6d\n", rand() );<BR>}<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -