static double gauss_rand(double mean, double sigma)
{
double x, y, r2;
do {
x = -1.0 + 2.0 * uniform_rand(0.0, 1.0);
y = -1.0 + 2.0 * uniform_rand(0.0, 1.0);
r2 = x * x + y * y;
} while (r2 > 1.0 || r2 == 0.0);
return mean + sigma * y * std::sqrt(-2.0 * log(r2) / r2);
}
/**
* sample a number from a uniform distribution
*/
static double uniform_rand(double lowerBndr, double upperBndr)
{
return lowerBndr + ((double) std::rand() / (RAND_MAX + 1.0)) * (upperBndr - lowerBndr);
}
/**
* default seed function using the current time in seconds
*/
static void seed_rand()
{
seed_rand(static_cast<unsigned int>(std::time(NULL)));
}
/** seed the random number generator */
static void seed_rand(unsigned int seed)
{
std::srand(seed);
}