共用方式為


binomial_distribution::binomial_distribution

建構散發。

binomial_distribution(result_type t0 = 1,
    const RealType& p0 = RealType(0.5));
explicit binomial_distribution(const param_type& par0);

參數

  • t0
    T 散發參數。

  • p0
    p 發出參數。

  • par0
    用於參數封裝建構散發。

備註

前置條件: 0.0 <= t0 && 0.0 <= p0 && p0 <= 1.0

第一個建構函式建構儲存值 stored_p 保留值 p0 ,並儲存值 stored_t 保留值 t0的物件。

第二個建構函式會將參數從 par0初始化的物件。

範例

 

// std_tr1__random__binomial_distribution_construct.cpp 
// compile with: /EHsc 
#include <random> 
#include <iostream> 
 
typedef std::mt19937 Myeng; 
typedef std::binomial_distribution<int, double> Mydist; 
int main() 
    { 
    Myeng eng; 
    Mydist dist(2, 0.6); 
    Mydist::input_type engval = eng(); 
    Mydist::result_type distval = dist(eng); 
 
    distval = distval;  // to quiet "unused" warnings 
    engval = engval; 
 
    std::cout << "p == " << dist.p() << std::endl; 
    std::cout << "t == " << dist.t() << std::endl; 
 
    dist.reset(); // discard any cached values 
    std::cout << "a random value == " << dist(eng) << std::endl; 
    std::cout << "a random value == " << dist(eng) << std::endl; 
    std::cout << "a random value == " << dist(eng) << std::endl; 
 
    return (0); 
    } 
 
  

需求

標題: <random>

命名空間: std

請參閱

參考

<random>

binomial_distribution Class