0
点赞
收藏
分享

微信扫一扫

C++产生随机数

朱悟能_9ad4 2022-04-16 阅读 30
c++
#include<iostream>
using namespace std;
int main()
{
	srand(time(0));       //设定随机数种子
	int x = rand();       //rand()生产0-RAND_MAX之间的随机整数
	
	//所以想要0-10之间的话,可以
	int x = rand()%11;    //0-10
	x = rand()%51-25;     //-25 - 25
	double y = rand()/RAND_MAX;  //0-1的随机小数
	return 0;
}
举报

相关推荐

0 条评论