Edit: Running the code on cpp.sh with "Standard Input option" set to "None" gives the same error, while setting it to "Interactive" works fine without any errors.
A normal distribution is not restricted within some finite limits. The first argument to the std::normal_distribution constructor is the mean, and the second argument is the standard deviation.
Ahh, thank you! I think I understand the problem now.
I was using std::normal_distribution constructor like std::uniform_int_distribution with a high and a low value but that's not how standard deviation works.
I was writing outside of my vector<int> and that was the cause of the error.
I've corrected my code, both the standard_distribution constructor and my for loop to make sure I'm not accessing invalid elements.
This code "works" but I just want to point out two things.
1. The std::normal_distribution can give you negative values. Your condition (d < histogram.size()) only happens to reject negative values because histogram.size() returns an unsigned integer type which forces d to be converted to an unsigned integer type (which turns negative values into large positive values) before the comparison takes place.
2. The std::normal_distribution returns floating-point values which you convert to integers by just throwing away the decimal part. This means that all values in the range (-1, 1) will map to 0 which makes 0 about twice as likely as it should be. For your current parameters it isn't easily noticeable but if you change line 19 to something like Rand_int rnd{5, 5}; you'll see a spike at 0 that shouldn't be there.