Compare random number distribution generators
The C++ Standard Library provides a selection of random number distribution generators, each with its own properties. In this recipe, we examine a function to compare the different options by creating a histogram of their output.
How to do it…
Like the random number engines, the distribution generators have some common interface elements. Unlike the random number engines, the distribution generators have a variety of properties to set. We can create a template function to print a histogram of the various distributions, but the initializations of the various distribution generators vary significantly:
- We start with some constants:
constexpr size_t n_samples{ 10 * 1000 }; constexpr size_t n_max{ 50 };
The n_samples
constant is the number of samples to generate for each histogram – in this case, 10,000.
The n_max
constant is used as a divisor while generating our histograms.
- Our histogram function...