首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::exponential_distribution

Defined in header <random>

?

?

template< class RealType = double > class exponential_distribution;

?

(since C++11)

产生随机非负浮点值x,按概率密度函数分布:P%28xλ%29=λe.

-λx

得到的值是下一个随机事件发生前的时间/距离,如果随机事件以每单位时间/距离的恒定速率λ发生。例如,这种分布描述了盖革计数器点击之间的时间或DNA链中点突变之间的距离。

这是连续对应的std::geometric_distribution...

std::exponential_distribution满足RandomNumberDistribution...

模板参数

RealType

-

The result type generated by the generator. The effect is undefined if this is not one of float, double, or long double.

成员类型

Member type

Definition

result_type

RealType

param_type

the type of the parameter set, see RandomNumberDistribution.

成员函数

(constructor)

constructs new distribution (public member function)

reset

resets the internal state of the distribution (public member function)

世代

运算符%28%29在分布%28公共成员函数%29中生成下一个随机数。

特征

Lambda返回lambda分布参数%28事件率%29%28公共成员函数%29

Param获取或设置分布参数对象%28公共成员函数%29

min返回最小潜在生成值%28公共成员函数%29

MAX返回最大潜在生成值%28公共成员函数%29

非会员职能

operator==operator!=

compares two distribution objects (function)

operator<<operator>>

performs stream input and output on pseudo-random number distribution (function template)

注记

一些实现可能偶尔返回无穷大,如果RealTypefloat这是lwg第2524期...

二次

代码语言:javascript
复制
#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';
    }
}

二次

可能的产出:

二次

代码语言:javascript
复制
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.“指数分布”来自MathWorld的一个Wolfram Web资源。

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com