您的位置:首页 > 运维架构 > Linux

linux下 C语言随机数生成方法rand(产生随机数)

2014-07-16 16:32 531 查看
求点击



srand初始化随机种子,rand产生随机数

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

main()

{

int i,j;

srand((int)time(0));

for(i=0;i<10;i++)
{
j=1+(int)(50.0*rand()/(RAND_MAX+1.0)); //50.0表示生成的随机数在0~50范围内

printf(" %d \n",j);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  rand srand 随机数 linux