uniform_real.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* boost random/uniform_real.hpp header file
  2. *
  3. * Copyright Jens Maurer 2000-2001
  4. * Distributed under the Boost Software License, Version 1.0. (See
  5. * accompanying file LICENSE_1_0.txt or copy at
  6. * http://www.boost.org/LICENSE_1_0.txt)
  7. *
  8. * See http://www.boost.org for most recent version including documentation.
  9. *
  10. * $Id$
  11. *
  12. * Revision history
  13. * 2001-04-08 added min<max assertion (N. Becker)
  14. * 2001-02-18 moved to individual header files
  15. */
  16. #ifndef BOOST_RANDOM_UNIFORM_REAL_HPP
  17. #define BOOST_RANDOM_UNIFORM_REAL_HPP
  18. #include <boost/assert.hpp>
  19. #include <boost/config.hpp>
  20. #include <boost/limits.hpp>
  21. #include <boost/random/uniform_real_distribution.hpp>
  22. namespace boost {
  23. /**
  24. * The distribution function uniform_real models a random distribution.
  25. * On each invocation, it returns a random floating-point value uniformly
  26. * distributed in the range [min..max).
  27. *
  28. * This class is deprecated. Please use @c uniform_real_distribution in
  29. * new code.
  30. */
  31. template<class RealType = double>
  32. class uniform_real : public random::uniform_real_distribution<RealType>
  33. {
  34. typedef random::uniform_real_distribution<RealType> base_type;
  35. public:
  36. class param_type : public base_type::param_type
  37. {
  38. public:
  39. typedef uniform_real distribution_type;
  40. /**
  41. * Constructs the parameters of a uniform_real distribution.
  42. *
  43. * Requires: min <= max
  44. */
  45. explicit param_type(RealType min_arg = RealType(0.0),
  46. RealType max_arg = RealType(1.0))
  47. : base_type::param_type(min_arg, max_arg)
  48. {}
  49. };
  50. /**
  51. * Constructs a uniform_real object. @c min and @c max are the
  52. * parameters of the distribution.
  53. *
  54. * Requires: min <= max
  55. */
  56. explicit uniform_real(RealType min_arg = RealType(0.0),
  57. RealType max_arg = RealType(1.0))
  58. : base_type(min_arg, max_arg)
  59. {
  60. BOOST_ASSERT(min_arg < max_arg);
  61. }
  62. /** Constructs a uniform_real distribution from its parameters. */
  63. explicit uniform_real(const param_type& parm)
  64. : base_type(parm)
  65. {}
  66. /** Returns the parameters of the distribution */
  67. param_type param() const { return param_type(this->a(), this->b()); }
  68. /** Sets the parameters of the distribution. */
  69. void param(const param_type& parm) { this->base_type::param(parm); }
  70. };
  71. } // namespace boost
  72. #endif // BOOST_RANDOM_UNIFORM_REAL_HPP