g2o
Static Public Member Functions | List of all members
g2o::tutorial::Rand Class Reference

generate random numbers More...

#include <rand.h>

Static Public Member Functions

static double gauss_rand (double mean, double sigma)
 
static double uniform_rand (double lowerBndr, double upperBndr)
 
static void seed_rand ()
 
static void seed_rand (unsigned int seed)
 

Detailed Description

generate random numbers

Definition at line 43 of file rand.h.

Member Function Documentation

static double g2o::tutorial::Rand::gauss_rand ( double  mean,
double  sigma 
)
inlinestatic

Gaussian random with a mean and standard deviation. Uses the Polar method of Marsaglia.

Definition at line 50 of file rand.h.

References uniform_rand().

51  {
52  double x, y, r2;
53  do {
54  x = -1.0 + 2.0 * uniform_rand(0.0, 1.0);
55  y = -1.0 + 2.0 * uniform_rand(0.0, 1.0);
56  r2 = x * x + y * y;
57  } while (r2 > 1.0 || r2 == 0.0);
58  return mean + sigma * y * std::sqrt(-2.0 * log(r2) / r2);
59  }
static double uniform_rand(double lowerBndr, double upperBndr)
Definition: rand.h:64
static void g2o::tutorial::Rand::seed_rand ( )
inlinestatic

default seed function using the current time in seconds

Definition at line 72 of file rand.h.

73  {
74  seed_rand(static_cast<unsigned int>(std::time(NULL)));
75  }
static void seed_rand()
Definition: rand.h:72
static void g2o::tutorial::Rand::seed_rand ( unsigned int  seed)
inlinestatic

seed the random number generator

Definition at line 78 of file rand.h.

79  {
80  std::srand(seed);
81  }
static double g2o::tutorial::Rand::uniform_rand ( double  lowerBndr,
double  upperBndr 
)
inlinestatic

sample a number from a uniform distribution

Definition at line 64 of file rand.h.

65  {
66  return lowerBndr + ((double) std::rand() / (RAND_MAX + 1.0)) * (upperBndr - lowerBndr);
67  }

The documentation for this class was generated from the following file: