Changing random.h to use cstdlib for Windows compability.

As discussed with Sameer today.

Change-Id: If3d0284830c6591c71cc77b8400cafb45c0da61f
This commit is contained in:
Petter Strandmark
2012-08-28 18:05:20 -07:00
parent aeb00a0732
commit 87ca1b2ba2
2 changed files with 4 additions and 24 deletions
-21
View File
@@ -273,27 +273,6 @@ void SetSolverOptionsFromFlags(BALProblem* bal_problem,
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();
+4 -3
View File
@@ -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;
}