Backported RNG_MT19937 from master.

This commit is contained in:
Roman Donchenko
2013-04-10 19:39:38 +04:00
parent f64d512774
commit 484607fb6f
3 changed files with 185 additions and 0 deletions

View File

@@ -2044,6 +2044,40 @@ public:
uint64 state;
};
/*!
Random Number Generator - MT
The class implements RNG using the Mersenne Twister algorithm
*/
class CV_EXPORTS RNG_MT19937
{
public:
RNG_MT19937();
RNG_MT19937(unsigned s);
void seed(unsigned s);
unsigned next();
operator int();
operator unsigned();
operator float();
operator double();
unsigned operator ()(unsigned N);
unsigned operator ()();
//! returns uniformly distributed integer random number from [a,b) range
int uniform(int a, int b);
//! returns uniformly distributed floating-point random number from [a,b) range
float uniform(float a, float b);
//! returns uniformly distributed double-precision floating-point random number from [a,b) range
double uniform(double a, double b);
private:
enum PeriodParameters {N = 624, M = 397};
unsigned state[N];
int mti;
};
/*!
Termination criteria in iterative algorithms