std::negative_binomial_distribution

来自cppreference.com
< cpp‎ | numeric‎ | random
2013年7月2日 (二) 10:21P12bot讨论 | 贡献的版本

 
 
 
 
 
在标头 <random> 定义
template< class IntType = int >
class negative_binomial_distribution;
(C++11 起)
产生随机的非负整数值i根据离散概率函数,分布:
原文:
Produces random non-negative integer values i, distributed according to discrete probability function:
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。
P(i|k,p) =

k + i − 1
i


· pk
· (1 − p)i
该值表示在一系列独立“是/否”试验失败的次数(每个成功的概率p),之前究竟发生k成功.
原文:
The value represents the number of failures in a series of independent yes/no trials (each succeeds with probability p), before exactly k successes occur.
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

目录

会员类型

会员类型
原文:
Member type
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。
Definition
result_type IntType
param_type
的类型的参数集,未指定
原文:
the type of the parameter set, unspecified
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

成员函数

构造新分布
(公开成员函数) [编辑]
(C++11)
重置分布的内部状态
(公开成员函数) [编辑]
原文:
Generation
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。
生成分布中的下个随机数
(公开成员函数) [编辑]
特性
原文:
Characteristics
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。
(C++11)
返回分布参数
(公开成员函数) [编辑]
(C++11)
返回分布参数
(公开成员函数) [编辑]
(C++11)
获取或设置随机参数对象
(公开成员函数) [编辑]
(C++11)
返回潜在生成的最小值
(公开成员函数) [编辑]
(C++11)
返回潜在生成的最大值
(公开成员函数) [编辑]

非成员函数

(C++11)(C++11)(C++20 移除)
比较两个分布对象
(函数) [编辑]
执行伪随机数分布的流输入和输出
(函数模板) [编辑]

为例

#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <random>
 
int main()
{
    std::random_device rd;
    std::mt19937 gen(rd());
    // Pat goes door-to-door selling cookies
    // At each house, there's a 75% chance that she sells one box
    // how many times will she be turned away before selling 5 boxes?
    std::negative_binomial_distribution<> d(5, 0.75);
 
    std::map<int, int> hist;
    for(int n=0; n<10000; ++n) {
        ++hist[d(gen)];
    }
    for(auto p : hist) {
        std::cout  << p.first << ' ' << std::string(p.second/100, '*') << '\n';
    }
}

输出:

0 ***********************
1 *****************************
2 **********************
3 *************
4 ******
5 ***
6 *
7 
8 
9 
10 
11

外部链接

Weisstein, Eric W. "Negative Binomial Distribution.",从MathWorld - Wolfram网络资源.
原文:
Weisstein, Eric W. "Negative Binomial Distribution." From MathWorld--A Wolfram Web Resource.
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。