22智能在线
新记
在C语言中如何产生随机数
如题所述
举报该文章
相关建议 2018-05-28
假设要生成的随机数是大于等于20且小于等于100的整数
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
void main() { int a,b,x;
a=20; b=100;
srand((unsigned int)time(NULL)); //用当前时间生成一个随机数种子
x=rand()%(b-a+1)+a;
printf("得到一个随机数:%d\n",x);
}
温馨提示:内容为网友见解,仅供参考
当前网址:
https://22.t2y.org/zz/fix0fx62c0c2ixf6xi.html
其他看法
无其他回答
相似回答
大家正在搜
相关问题
C语言怎样产生一定范围的随机数?
如何用c语言产生一定范围内的随机数?
c语言中如何产生1或0随机数
c语言,如何产生随机数
C语言中产生随机数
C语言中如何产生一个随机数及其原理
C语言中怎样生成随机数?
c语言怎么生成随机数?