1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP
12 #define BOOST_COMPUTE_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP
14 #include <boost/assert.hpp>
15 #include <boost/type_traits.hpp>
17 #include <boost/compute/command_queue.hpp>
18 #include <boost/compute/function.hpp>
19 #include <boost/compute/detail/literal.hpp>
20 #include <boost/compute/types/fundamental.hpp>
25 /// \class uniform_real_distribution
26 /// \brief Produces uniformly distributed random floating-point numbers.
28 /// The following example shows how to setup a uniform real distribution to
29 /// produce random \c float values between \c 1 and \c 100.
31 /// \snippet test/test_uniform_real_distribution.cpp generate
33 /// \see default_random_engine, normal_distribution
34 template<class RealType = float>
35 class uniform_real_distribution
38 typedef RealType result_type;
40 /// Creates a new uniform distribution producing numbers in the range
43 uniform_real_distribution(RealType a = 0.f, RealType b = 1.f)
50 /// Destroys the uniform_real_distribution object.
51 ~uniform_real_distribution()
55 /// Returns the minimum value of the distribution.
61 /// Returns the maximum value of the distribution.
67 /// Generates uniformly distributed floating-point numbers and stores
68 /// them to the range [\p first, \p last).
69 template<class OutputIterator, class Generator>
70 void generate(OutputIterator first,
75 BOOST_COMPUTE_FUNCTION(RealType, scale_random, (const uint_ x),
77 return nextafter(LO + (convert_RealType(x) / MAX_RANDOM) * (HI - LO), (RealType) LO);
80 scale_random.define("LO", detail::make_literal(m_a));
81 scale_random.define("HI", detail::make_literal(m_b));
82 scale_random.define("MAX_RANDOM", "UINT_MAX");
84 "convert_RealType", std::string("convert_") + type_name<RealType>()
86 scale_random.define("RealType", type_name<RealType>());
89 first, last, scale_random, queue
93 /// \internal_ (deprecated)
94 template<class OutputIterator, class Generator>
95 void fill(OutputIterator first,
100 generate(first, last, g, queue);
107 BOOST_STATIC_ASSERT_MSG(
108 boost::is_floating_point<RealType>::value,
109 "Template argument must be a floating point type"
113 } // end compute namespace
114 } // end boost namespace
116 #endif // BOOST_COMPUTE_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP