-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
C++20 STL Cookbook
By :
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.
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:
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.