sl@0: /* boost random/exponential_distribution.hpp header file sl@0: * sl@0: * Copyright Jens Maurer 2000-2001 sl@0: * Distributed under the Boost Software License, Version 1.0. (See sl@0: * accompanying file LICENSE_1_0.txt or copy at sl@0: * http://www.boost.org/LICENSE_1_0.txt) sl@0: * sl@0: * See http://www.boost.org for most recent version including documentation. sl@0: * sl@0: * $Id: exponential_distribution.hpp,v 1.16 2004/07/27 03:43:32 dgregor Exp $ sl@0: * sl@0: * Revision history sl@0: * 2001-02-18 moved to individual header files sl@0: */ sl@0: sl@0: #ifndef BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP sl@0: #define BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: namespace boost { sl@0: sl@0: // exponential distribution: p(x) = lambda * exp(-lambda * x) sl@0: template sl@0: class exponential_distribution sl@0: { sl@0: public: sl@0: typedef RealType input_type; sl@0: typedef RealType result_type; sl@0: sl@0: #if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300) sl@0: BOOST_STATIC_ASSERT(!std::numeric_limits::is_integer); sl@0: #endif sl@0: sl@0: explicit exponential_distribution(result_type lambda = result_type(1)) sl@0: : _lambda(lambda) { assert(lambda > result_type(0)); } sl@0: sl@0: // compiler-generated copy ctor and assignment operator are fine sl@0: sl@0: result_type lambda() const { return _lambda; } sl@0: sl@0: void reset() { } sl@0: sl@0: template sl@0: result_type operator()(Engine& eng) sl@0: { sl@0: #ifndef BOOST_NO_STDC_NAMESPACE sl@0: using std::log; sl@0: #endif sl@0: return -result_type(1) / _lambda * log(result_type(1)-eng()); sl@0: } sl@0: sl@0: #if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) sl@0: template sl@0: friend std::basic_ostream& sl@0: operator<<(std::basic_ostream& os, const exponential_distribution& ed) sl@0: { sl@0: os << ed._lambda; sl@0: return os; sl@0: } sl@0: sl@0: template sl@0: friend std::basic_istream& sl@0: operator>>(std::basic_istream& is, exponential_distribution& ed) sl@0: { sl@0: is >> std::ws >> ed._lambda; sl@0: return is; sl@0: } sl@0: #endif sl@0: sl@0: private: sl@0: result_type _lambda; sl@0: }; sl@0: sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP