Eigen template library Random() method algorithm

195 views Asked by At

does anyone know, which algorithm the Eigen library for C++ uses in the method Random():

eigen - random() doc

?

If eigen passes this decision on to the compiler (using its standard method to create pseudo random numbers), than I would like to know which algorithm g++ (gcc49 4.9.2_2) uses as default.

Any helpful hint is much appreciated.

1

There are 1 answers

0
Avi Ginsburg On

As Paul R pointed out, the default is to just call rand. If you look in Eigen/src/Core/MathFunctions.h you'll find the default:

template<typename Scalar>
struct random_default_impl<Scalar, false, false>
{
  static inline Scalar run(const Scalar& x, const Scalar& y)
  {
    return x + (y-x) * Scalar(std::rand()) / Scalar(RAND_MAX);
  }
  static inline Scalar run()
  {
    return run(Scalar(NumTraits<Scalar>::IsSigned ? -1 : 0), Scalar(1));
  }
};

or variants on the theme (for different variable types).