stl c++11 solution :
auto distribution = std::bind(std::normal_distribution<double>{mean, stddev},
std::mt19937(std::random_device{}())
);
std::transform(data.begin(), data.end(), data.begin(),
std::bind(std::plus<double>(), std::placeholders::_1, distribution()));
Easy range-based loop :
for (auto& d : data) {
d += distribution();
}
My STL solution doesn't work as it always take the first number it generated from the distribution. I tried with the placeholder as the 3rd parameter but it doesn't change anything. All of my data is incremented by the same number which is not something I want. I want the same behaviour as the range-based loop.
It this something possible?