diff --git a/src/caffe/util/math_functions.cpp b/src/caffe/util/math_functions.cpp index 2a0c7c4e453..07b1aa01fd7 100644 --- a/src/caffe/util/math_functions.cpp +++ b/src/caffe/util/math_functions.cpp @@ -398,12 +398,15 @@ void caffe_vRngUniform(const int n, Dtype* r, // FIXME check if boundaries are handled in the same way ? // Fixed by caffe_nextafter - boost::random::uniform_real_distribution random_distribution( + boost::uniform_real random_distribution( a, caffe_nextafter(b)); Caffe::random_generator_t &generator = Caffe::vsl_stream(); + boost::variate_generator > variate_generator( + generator, random_distribution); - for(int i = 0; i < n; i += 1) { - r[i] = random_distribution(generator); + for (int i = 0; i < n; ++i) { + r[i] = variate_generator(); } } @@ -431,9 +434,12 @@ void caffe_vRngGaussian(const int n, Dtype* r, const Dtype a, // the tests are irrelevant to the random numbers. boost::normal_distribution random_distribution(a, sigma); Caffe::random_generator_t &generator = Caffe::vsl_stream(); + boost::variate_generator > variate_generator( + generator, random_distribution); - for(int i = 0; i < n; i += 1) { - r[i] = random_distribution(generator); + for (int i = 0; i < n; ++i) { + r[i] = variate_generator(); } } @@ -454,9 +460,12 @@ void caffe_vRngBernoulli(const int n, Dtype* r, const double p) { // FIXME check if parameters are handled in the same way ? boost::bernoulli_distribution random_distribution(p); Caffe::random_generator_t &generator = Caffe::vsl_stream(); + boost::variate_generator > variate_generator( + generator, random_distribution); - for(int i = 0; i < n; i += 1) { - r[i] = random_distribution(generator); + for (int i = 0; i < n; ++i) { + r[i] = variate_generator(); } }