ExRandom  3.0
Getting started
Back to Simple examples. Forward to Compiling all the examples. Up to Contents.

Prerequisites:

  • a C++ compiler which supports C++11. The library has been tested on Linux and MacOSX (with the -std=c++11 flag) and Windows (Visual Studio 14 and later). All the examples should compile with no warning messages.
  • a good source of uniform random numbers. For every day use, I recommend the Mersenne Twister std::mt19937 (reseeded with each use, of course). Alternatively, if std::random_device is hooked up to a hardware generator (check the value of entropy()), then that can be used.

If you just want to use the library to get at accurate random deviates, then you should use the interfaces providing C++11 random distributions. These work in exactly the same manner as, for example, std::normal_distribution. The distributions provided are

The first three distributions are templated and can return any floating point type. The last distribution returns ints.

The entire library is header-only. Thus all you have to do is set the include path to the parent directory containing the exrandom include directory. Everything is in the exrandom namespace. So the typical invocation is

#include <random>
...
auto g = std::mt19937(std::random_device()());
double x = N(g); // a normal deviate
...
Back to Simple examples. Forward to Compiling all the examples. Up to Contents.