Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion include/boost/compute/random/uniform_real_distribution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ class uniform_real_distribution

/// Creates a new uniform distribution producing numbers in the range
/// [\p a, \p b).
/// Requires a < b
uniform_real_distribution(RealType a = 0.f, RealType b = 1.f)
: m_a(a),
m_b(b)
{
BOOST_ASSERT(a < b);
}

/// Destroys the uniform_real_distribution object.
Expand Down Expand Up @@ -69,7 +71,9 @@ class uniform_real_distribution
{
BOOST_COMPUTE_FUNCTION(RealType, scale_random, (const uint_ x),
{
return LO + (convert_RealType(x) / MAX_RANDOM) * (HI - LO);
// Use nextafter to shift the result slightly towards LO to avoid being able to get a
// value of exactly HI.
return nextafter(LO + (convert_RealType(x) / MAX_RANDOM) * (HI - LO), LO);
});

scale_random.define("LO", detail::make_literal(m_a));
Expand Down