why??????

lhgyes 2000-08-29 04:34:00
srand()是何用?
...全文
100 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hoyle 2000-08-30
  • 打赏
  • 举报
回复
srand是使用用户的参数作为种子来产生伪随机数的一个函数
种子的选取影响到随机数的产生

srand 和random的区别在于,random不需要由用户指定种子,所以
如果在使用random 之前没有执行randomize,那么random每次产生的随机数序列都是一样的
hoyle 2000-08-30
  • 打赏
  • 举报
回复
srand是使用用户的参数作为种子来产生伪随机数的一个函数
种子的选取影响到随机数的产生
huntout 2000-08-29
  • 打赏
  • 举报
回复
Sets a random starting point.

Example

/* RAND.C: This program seeds the random-number generator
* with the time, then displays 10 random integers.
*/

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

void main( void )
{
int i;

/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );

/* Display 10 numbers. */
for( i = 0; i < 10;i++ )
printf( " %6d\n", rand() );
}


69,364

社区成员

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

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