std::uniform_real_distribution inclusive range

前端 未结 2 1868
挽巷
挽巷 2020-12-31 19:09

C++11 std::uniform_real_distribution( -1, 1 ) gives numbers in the range [-1,1).

How would you get a uniform real distribution in the range [-1,1]?

Practical

2条回答
  •  感情败类
    2020-12-31 19:22

    Unfortunately the actual implementations of the floating point distributions don't allow you to be so precise. E.g., uniform_real_distribution is supposed to produce values in a given half range, but due to rounding issues it may in fact produce values in an inclusive range instead.

    Here's an example of the problem with generate_cannonical, and similar problems occur with the other real_distributions.

提交回复
热议问题