1 /* boost random/exponential_distribution.hpp header file
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)
8 * See http://www.boost.org for most recent version including documentation.
10 * $Id: exponential_distribution.hpp,v 1.16 2004/07/27 03:43:32 dgregor Exp $
13 * 2001-02-18 moved to individual header files
16 #ifndef BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
17 #define BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
22 #include <boost/limits.hpp>
23 #include <boost/static_assert.hpp>
27 // exponential distribution: p(x) = lambda * exp(-lambda * x)
28 template<class RealType = double>
29 class exponential_distribution
32 typedef RealType input_type;
33 typedef RealType result_type;
35 #if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300)
36 BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
39 explicit exponential_distribution(result_type lambda = result_type(1))
40 : _lambda(lambda) { assert(lambda > result_type(0)); }
42 // compiler-generated copy ctor and assignment operator are fine
44 result_type lambda() const { return _lambda; }
48 template<class Engine>
49 result_type operator()(Engine& eng)
51 #ifndef BOOST_NO_STDC_NAMESPACE
54 return -result_type(1) / _lambda * log(result_type(1)-eng());
57 #if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
58 template<class CharT, class Traits>
59 friend std::basic_ostream<CharT,Traits>&
60 operator<<(std::basic_ostream<CharT,Traits>& os, const exponential_distribution& ed)
66 template<class CharT, class Traits>
67 friend std::basic_istream<CharT,Traits>&
68 operator>>(std::basic_istream<CharT,Traits>& is, exponential_distribution& ed)
70 is >> std::ws >> ed._lambda;
81 #endif // BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP