Skip to content

Commit

Permalink
Merge pull request opencv#6332 from sovrasov:python_rng_seed
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Mar 29, 2016
2 parents 1e1dc14 + 72ed417 commit ff0d115
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions modules/core/include/opencv2/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,14 @@ is much faster to use this function to retrieve the generator and then use RNG::
*/
CV_EXPORTS RNG& theRNG();

/** @brief Sets state of default random number generator.
The function sets state of default random number generator to custom value.
@param seed new state for default random number generator
@sa RNG, randu, randn
*/
CV_EXPORTS_W void setRNGSeed(int seed);

/** @brief Generates a single uniformly-distributed random number or an array of random numbers.
Non-template variant of the function fills the matrix dst with uniformly-distributed
Expand Down
6 changes: 6 additions & 0 deletions modules/core/src/rand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,12 @@ cv::RNG& cv::theRNG()
return getCoreTlsData().get()->rng;
}

void cv::setRNGSeed(int seed)
{
theRNG() = RNG(static_cast<uint64>(seed));
}


void cv::randu(InputOutputArray dst, InputArray low, InputArray high)
{
theRNG().fill(dst, RNG::UNIFORM, low, high);
Expand Down
1 change: 1 addition & 0 deletions modules/python/test/tests_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def get_sample(self, filename, iscolor = cv2.IMREAD_COLOR):
return self.image_cache[filename]

def setUp(self):
cv2.setRNGSeed(10)
self.image_cache = {}

def hashimg(self, im):
Expand Down

0 comments on commit ff0d115

Please sign in to comment.