you could use your own instead) and using RNG::operator T() to get your random numbers (more on
that operator follows).
cv::RNG()
cv::RNG::RNG( void );
cv::RNG::RNG( uint64 state ); // create using the seed ‘state’
You can create an RNG object with either the default constructor, or you can pass it a 64-bit unsigned
integer that it will use as the seed of the random number sequence. If you call the default constructor (or
pass 0 to the second variation) the generator will initialize with a standardized value.
47
cv::RNG::operator T()
cv::RNG::operator uchar();
cv::RNG::operator schar();
cv::RNG::operator ushort();
cv::RNG::operator short int();
cv::RNG::operator int();
cv::RNG::operator unsigned();
cv::RNG::operator float();
cv::RNG::operator double();
This is really a set of different methods that return a new random number from cv::RNG of some specific
type. Each of these is an overloaded cast operator, so in effect you cast the RNG object to whatever type
you want:
Example 3-2: Using the default random number generator we generate a pair of integers and a pair of
floating-point numbers; the style of the cast operation is up to you, this example shows both the int(x)
and the (int)x forms
cv::RNG rng = cv::theRNG();
cout << ”An integer: “ << (int)rng << endl;
cout << ”Another integer: “ << int(rng) << endl;
cout << ”A float: “ << (float)rng << endl;
cout <<