-
Notifications
You must be signed in to change notification settings - Fork 960
Closed
Description
In the "in One Weekend" book chapter 7, the book introduced the usage of the <random> header. The current function looks like this:
inline double random_double_2() {
static std::uniform_real_distribution<double> distribution(0.0, 1.0);
static std::mt19937 generator;
static std::function<double()> rand_generator =
std::bind(distribution, generator);
return rand_generator();
}The usage of std::function and std::bind are unnecessary, and the book also does not have any explanation on it. The following function should be functional equivalent, but also easier to understand for people not familiar with those standard library constructs:
inline double random_double_2() {
static std::uniform_real_distribution<double> distribution(0.0, 1.0);
static std::mt19937 generator;
return distribution(generator);
}If you want me to change that, I can create a PR.