std::exponential_distribution
来自cppreference.com
![]() |
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <random> 中定义
|
||
template< class RealType = double > class exponential_distribution; |
(C++11 起) | |
产生随机非负浮点值x,根据概率密度函数分布
原文:
Produces random non-negative floating-point values x, distributed according to probability density function:
- P(x|λ) = λe-λx
获得的值,直到下一次的随机事件,如果随机事件发生在恒定的速率λ每单位时间/距离的时间/距离。例如,此分布描述盖格计数器的点击或点突变的DNA链之间的距离之间的时间.
原文:
The value obtained is the time/distance until the next random event if random events occur at constant rate λ per unit of time/distance. For example, this distribution describes the time between the clicks of a Geiger counter or the distance between point mutations in a DNA strand.
这是连续对应的std::geometric_distribution
原文:
This is the continuous counterpart of std::geometric_distribution
目录 |
[编辑] 会员类型
会员类型
|
Definition |
result_type
|
RealType |
param_type
|
的类型的参数集,未指定
原文: the type of the parameter set, unspecified |
[编辑] 成员函数
构建新的分配 (公共成员函数) | |
复位内部状态的分布 原文: resets the internal state of the distribution (公共成员函数) | |
| |
生成下一个随机数的分布 原文: generates the next random number in the distribution (公共成员函数) | |
| |
返回“拉姆达”分布参数(事件率) 原文: returns the lambda distribution parameter (rate of events) (公共成员函数) | |
获取或设置的分布参数对象 原文: gets or sets the distribution parameter object (公共成员函数) | |
返回的最低可能产生的价值 原文: returns the minimum potentially generated value (公共成员函数) | |
返回的最大潜在价值 原文: returns the maximum potentially generated value (公共成员函数) |
[编辑] 非成员函数
比较两个分布对象 (函数) | |
执行流输入和输出的伪随机数分布 原文: performs stream input and output on pseudo-random number distribution (函数) |
[编辑] 示例
#include <iostream> #include <iomanip> #include <string> #include <map> #include <random> int main() { std::random_device rd; std::mt19937 gen(rd()); // if particles decay once per second on average, // how much time, in seconds, until the next one? std::exponential_distribution<> d(1); std::map<int, int> hist; for(int n=0; n<10000; ++n) { ++hist[2*d(gen)]; } for(auto p : hist) { std::cout << std::fixed << std::setprecision(1) << p.first/2.0 << '-' << (p.first+1)/2.0 << ' ' << std::string(p.second/200, '*') << '\n'; }
输出:
0.0-0.5 ******************* 0.5-1.0 *********** 1.0-1.5 ******* 1.5-2.0 **** 2.0-2.5 ** 2.5-3.0 * 3.0-3.5 3.5-4.0
[编辑] 外部链接
Weisstein, Eric W. "Exponential Distribution.",从MathWorld - Wolfram网络资源.
原文:
Weisstein, Eric W. "Exponential Distribution." From MathWorld--A Wolfram Web Resource.