/*!
Random Number Generator
The class implements RNG using Multiply-with-Carry algorithm
*/
class CV_EXPORTS RNG
{
public:
enum { UNIFORM=0, NORMAL=1 };
RNG();//默认构造函数
// inline RNG::RNG() { state = 0xffffffff; }
RNG(uint64 state);//带参数的构造函数,接受一个64位无符号的值。
//inline RNG::RNG(uint64 _state) { state = _state ? _state : 0xffffffff; }
//! updates the state and returns the next 32-bit unsigned integer random number
unsigned next();
/*
inline unsigned RNG::next()
{
state = (uint64)(unsigned)state*CV_RNG_COEFF + (unsigned)(state >> 32);
return (unsigned)state;
}
#define CV_RNG_COEFF 4164903690U
用两个很大的无符号数相乘,乘积结果要转换为64位无符号数,转换的时候两个乘数应该向高精度看起,所以应该也先转换为64位再相乘。把state右移32位得到一个数,把这两个数相加。函数返回一个32位的无符号数,其值为截断前面求得的和。
*/
//以下几个函数是从类到uchar.schar,ushort,short,usinged的显示转换函数
operator uchar();//返回一个8位无符号类型的随机数,把next返回的数截断
//inline RNG::ope
OpenCV之随机类RNG
最新推荐文章于 2024-07-31 11:33:01 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)