如要产生[m,n]范围内的随机数num,可用:
int num=rand()%(n-m+1)+m;
在main函数中定义:srand((unsigned int)time(NULL));//定义一个随机种子,让产生的随机数随着电脑时间的变化而变化,但要加头文件:"include<ctime>"
产生随机数
最新推荐文章于 2025-05-21 21:44:07 发布
如要产生[m,n]范围内的随机数num,可用:
int num=rand()%(n-m+1)+m;
在main函数中定义:srand((unsigned int)time(NULL));//定义一个随机种子,让产生的随机数随着电脑时间的变化而变化,但要加头文件:"include<ctime>"