» 首页 » 电脑_数码 » 编程 » 伯努利分布C++程序

伯努利分布C++程序

我急着要伯努利分布的C++程序啊,还有突发流量的……
哪位知道的给我一下啊~十万火急~先谢谢了~
我刚来,分数比较少,全部赏出去,大家帮忙啊~


boost/random/bernoulli_distribution.hpp
/* boost random/bernoulli_distribution.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id: bernoulli_distribution.hpp 41369 2007-11-25 18:07:19Z bemandawes $
*
* Revision history
* 2001-02-18 moved to individual header files
*/

#ifndef BOOST_RANDOM_BERNOULLI_DISTRIBUTION_HPP
#define BOOST_RANDOM_BERNOULLI_DISTRIBUTION_HPP

#include <cassert>
#include <iostream>

namespace boost {

// Bernoulli distribution: p(true) = p, p(false) = 1-p (boolean)
template<class RealType = double>
class bernoulli_distribution
{
public:
// In principle, this could work with both integer and floating-point
// types. Generating floating-point random numbers in the first
// place is probably more expensive, so use integer as input.
typedef int input_type;
typedef bool result_type;

explicit bernoulli_distribution(const RealType& p_arg = RealType(0.5))
: _p(p_arg)
{
assert(_p >= 0);
assert(_p <= 1);
}

// compiler-generated copy ctor and assignment operator are fine

RealType p() const { return _p; }
void reset() { }

template<class Engine>
result_type operator()(Engine& eng)
{
if(_p == RealType(0))
return false;
else
return RealType(eng() - (eng.min)()) <= _p * RealType((eng.max)()-(eng.min)());
}

#if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os, const bernoulli_distribution& bd)
{
os << bd._p;
return os;
}

template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, bernoulli_distribution& bd)
{
is >> std::ws >> bd._p;
return is;
}
#endif

private:
RealType _p;
};

} // namespace boost

#endif // BOOST_RANDOM_BERNOULLI_DISTRIBUTION_HPP

参考资料:http://www.boost.org/doc/libs/1_35_0/boost/random/bernoulli_distribution.hpp

 相关问题
·伯努利分布C++程序
·高分求助,用SQL与ASP或者VB开发简单的客房管理系统
·谁能给我推荐一本有关编程入门的书?
·asp读取access数据库主题
·asp.net堆栈跟踪
·我发觉我语言表达有问题,怎么办?
·SQL SERVER 服务器中,如何查询所有的数据库?并把数据库...
·怎样用asp判断一个URL地址是否存在有效??
·随滚动条上下移动的flash代码
·vs2005 网站开发的控件定义文件在哪里
·求php集成安装包( 优化、安全设置)都做好了的
·php代码 在自己的电脑上运行 需要什么
·VBS如何执行带\"\"的cmd命令
·SQL高手快来啊!!!
·紧急!!!编写程序:输入一行字符,统计其有多少个单词,单词...

 《伯努利分布C++程序》答案收集时间:2008-06-14 14:47:50



©2007 电脑技术问答录