40
40
namespace cvflann
41
41
{
42
42
43
+ inline int rand ()
44
+ {
45
+ #ifndef OPENCV_FLANN_USE_STD_RAND
46
+ # if INT_MAX == RAND_MAX
47
+ int v = cv::theRNG ().next () & INT_MAX;
48
+ # else
49
+ int v = cv::theRNG ().uniform (0 , RAND_MAX + 1 );
50
+ # endif
51
+ #else
52
+ int v = std::rand ();
53
+ #endif // OPENCV_FLANN_USE_STD_RAND
54
+ return v;
55
+ }
56
+
43
57
/* *
44
58
* Seeds the random number generator
45
59
* @param seed Random seed
46
60
*/
47
61
inline void seed_random (unsigned int seed)
48
62
{
49
- srand (seed);
63
+ #ifndef OPENCV_FLANN_USE_STD_RAND
64
+ cv::theRNG () = cv::RNG (seed);
65
+ #else
66
+ std::srand (seed);
67
+ #endif
50
68
}
51
69
52
70
/*
@@ -60,7 +78,7 @@ inline void seed_random(unsigned int seed)
60
78
*/
61
79
inline double rand_double (double high = 1.0 , double low = 0 )
62
80
{
63
- return low + ((high-low) * (std:: rand () / (RAND_MAX + 1.0 )));
81
+ return low + ((high-low) * (rand () / (RAND_MAX + 1.0 )));
64
82
}
65
83
66
84
/* *
@@ -71,7 +89,7 @@ inline double rand_double(double high = 1.0, double low = 0)
71
89
*/
72
90
inline int rand_int (int high = RAND_MAX, int low = 0 )
73
91
{
74
- return low + (int ) ( double (high-low) * (std:: rand () / (RAND_MAX + 1.0 )));
92
+ return low + (int ) ( double (high-low) * (rand () / (RAND_MAX + 1.0 )));
75
93
}
76
94
77
95
/* *
@@ -107,7 +125,11 @@ class UniqueRandom
107
125
for (int i = 0 ; i < size_; ++i) vals_[i] = i;
108
126
109
127
// shuffle the elements in the array
128
+ #ifndef OPENCV_FLANN_USE_STD_RAND
129
+ cv::randShuffle (vals_);
130
+ #else
110
131
std::random_shuffle (vals_.begin (), vals_.end ());
132
+ #endif
111
133
112
134
counter_ = 0 ;
113
135
}
0 commit comments