OpenCV 之 RNG rng(12345)


此类用于产生随机数


rng.uniform(1, 3);     在[1,3)区间,随机生成一个整数


#include "stdafx.h"
#include<iostream>
#include "opencv2/highgui/highgui.hpp"

using namespace cv;
using namespace std;

RNG rng(1234); //构造方法设定一个具体值,表示下面代码每次生成的结果都是一样的

int main()
{
	for (int i = 0; i < 10; i++) {
		int a = rng.uniform(1, 200);  //从[1,200)范围内随机一个值
		cout << a << endl;
	}
	getchar();
	return 0;
}

RNG rng(1234);      如果改成   RNG rng((unsigned)time(NULL));  代码每次运行结果都不一样



 

FR:徐海涛(hunk Xu)

猜你喜欢

转载自blog.csdn.net/qq_15267341/article/details/88935514