opencv中的RNG类的用法

next取出下一个随机数

cv::RNG rng;
for (int i = 0; i < 5; i++)
{
	std::cout << rng.next() << "\n";
}
输出:

130063606
3003295397
3870020839
1350273629
4024955497
uniform函数返回指定范围的随机数

cv::RNG rng;
for (int i = 0; i < 5; i++)
{
int ret = rng.uniform(1, 10);
std::cout << ret<<"\n";
}
输出:
8
6
5
3
5

double uniform(double a, double b); //[a,b)内随机产生一个double型值

int uniform(int a, int b); //[a,b)内随机产生一个int型值

float uniform(float a, float b); //[a,b)内随机产生一个float型值
gaussian函数返回一个均值为0的高斯随机数

cv::RNG rng;
double gas = rng.gaussian(0.5); //σ =0.5 
std::cout << gas;

输出:
-8.01547e-10

你可能感兴趣的:(C++学习)