srand() ??

993305 2003-04-24 11:13:41
srand (void seed)

参数 seed 是什么意思,怎么取值呀?
...全文
73 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
delphihero 2003-04-24
  • 打赏
  • 举报
回复
设置随即数种子,不然随机就有规律了
#include <time.h>
srand( (unsigned)time( NULL ) );
for( i = 0; i < 10;i++ )
cout<<rand()<<endl;

Phlip 2003-04-24
  • 打赏
  • 举报
回复
seed是随机种子数.为了达到随机种子数每次不同的目的,一般用获取系统时间的方法.
srand(time(NULL))
huigll 2003-04-24
  • 打赏
  • 举报
回复
srand(unsigned int seed ) ;

srand( (unsigned)time( NULL ) );
linxuj99 2003-04-24
  • 打赏
  • 举报
回复
楼上同志:rand()/100%range+min中/100没有用的!
yiminggw 2003-04-24
  • 打赏
  • 举报
回复
//在一定范围内的随机数!
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void main()
{
int min,max,i;
srand(unsigned seed=time(NULL));
cout<<"input min and max number :"<<endl;
cin>>min>>max;
int range=max-min+1;
for(i=0;i<20;i++)
{
int r=rand()/100%range+min;
cout<<r<<" ";
}
cout<<endl;
}
hzflss 2003-04-24
  • 打赏
  • 举报
回复
产生一个随机数
Januarius_ 2003-04-24
  • 打赏
  • 举报
回复
伪随机数,先下一个种子,然后就可以产生随机数了
#include <time.h>
srand(time(NULL));
int a = rand();
shishiXP 2003-04-24
  • 打赏
  • 举报
回复
srand(数);
rand();

数变, rand()就变

70,037

社区成员

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

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