Changing random.h to use cstdlib for Windows compability. As discussed with Sameer today. Change-Id: If3d0284830c6591c71cc77b8400cafb45c0da61f
diff --git a/examples/bundle_adjuster.cc b/examples/bundle_adjuster.cc index 68458a0..f5c1ac1 100644 --- a/examples/bundle_adjuster.cc +++ b/examples/bundle_adjuster.cc
@@ -273,27 +273,6 @@ SetOrdering(bal_problem, options); } -// Uniform random numbers between 0 and 1. -double UniformRandom() { - return static_cast<double>(random()) / static_cast<double>(RAND_MAX); -} - -// Normal random numbers using the Box-Mueller algorithm. Its a bit -// wasteful, as it generates two but only returns one. -double RandNormal() { - double x1, x2, w, y1, y2; - do { - x1 = 2.0 * UniformRandom() - 1.0; - x2 = 2.0 * UniformRandom() - 1.0; - w = x1 * x1 + x2 * x2; - } while ( w >= 1.0 ); - - w = sqrt((-2.0 * log(w)) / w); - y1 = x1 * w; - y2 = x2 * w; - return y1; -} - void BuildProblem(BALProblem* bal_problem, Problem* problem) { const int point_block_size = bal_problem->point_block_size(); const int camera_block_size = bal_problem->camera_block_size();
diff --git a/internal/ceres/random.h b/internal/ceres/random.h index cd7a0ea..352c003 100644 --- a/internal/ceres/random.h +++ b/internal/ceres/random.h
@@ -34,19 +34,20 @@ #include <cmath> #include <cstdlib> +#include "ceres/internal/port.h" namespace ceres { inline void SetRandomState(int state) { - srandom(state); + srand(state); } inline int Uniform(int n) { - return random() % n; + return rand() % n; } inline double RandDouble() { - double r = static_cast<double>(random()); + double r = static_cast<double>(rand()); return r / RAND_MAX; }