共用方式為


geometric_distribution::geometric_distribution

建構散發。

geometric_distribution(RealType p0 = RealType(0.5));
explicit geometric_distribution(const param_type& par0);

參數

  • p0
    p 發出參數。

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

備註

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

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

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

範例

 

// std_tr1__random__geometric_distribution_construct.cpp 
// compile with: /EHsc 
#include <random> 
#include <iostream> 
 
typedef std::mt19937 Myeng; 
typedef std::geometric_distribution<int, double> Mydist; 
int main() 
    { 
    Myeng eng; 
    Mydist dist(0.1); 
    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; 
 
    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>

geometric_distribution Class