geometric_distribution 클래스
기하 분포를 생성합니다.
template<class IntType = int> class geometric_distribution { public: // types typedef IntType result_type; struct param_type; // constructors and reset functions explicit geometric_distribution(double p = 0.5); explicit geometric_distribution(const param_type& parm); void reset(); // generating functions template<class URNG> result_type operator()(URNG& gen); template<class URNG> result_type operator()(URNG& gen, const param_type& parm); // property functions double p() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; };
매개 변수
- IntType
정수 결과 형식으로, 기본적으로 int로 지정되어 있습니다. 가능한 형식은 <random>을 참조하세요.
설명
템플릿 클래스는 기하 분포를 사용하여 사용자 지정 정수 형식의 값을 생성하는 분포를 설명합니다. 다음 테이블은 개별 멤버에 대한 문서와 연결되어 있습니다.
geometric_distribution::p |
geometric_distribution::param |
|
geometric_distribution::operator() |
속성 함수 p()은 저장된 분포 매개 변수 p의 값을 반환합니다.
분포 클래스 및 이러한 클래스의 멤버에 대한 자세한 내용은 <random>을 참조하세요.
카이 제곱 분포에 대한 자세한 내용은 Wolfram MathWorld 문서 기하 분포를 참조하세요.
예제
// compile with: /EHsc /W4
#include <random>
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
void test(const double p, const int s) {
// uncomment to use a non-deterministic generator
// std::random_device gen;
std::mt19937 gen(1701);
std::geometric_distribution<> distr(p);
std::cout << std::endl;
std::cout << "min() == " << distr.min() << std::endl;
std::cout << "max() == " << distr.max() << std::endl;
std::cout << "p() == " << std::fixed << std::setw(11) << std::setprecision(10) << distr.p() << std::endl;
// generate the distribution as a histogram
std::map<int, int> histogram;
for (int i = 0; i < s; ++i) {
++histogram[distr(gen)];
}
// print results
std::cout << "Distribution for " << s << " samples:" << std::endl;
for (const auto& elem : histogram) {
std::cout << std::setw(5) << elem.first << ' ' << std::string(elem.second, ':') << std::endl;
}
std::cout << std::endl;
}
int main()
{
double p_dist = 0.5;
int samples = 100;
std::cout << "Use CTRL-Z to bypass data entry and run using default values." << std::endl;
std::cout << "Enter a floating point value for the \'p\' distribution parameter: ";
std::cin >> p_dist;
std::cout << "Enter an integer value for the sample count: ";
std::cin >> samples;
test(p_dist, samples);
}
출력
첫 번째 테스트:
두 번째 테스트:
요구 사항
헤더: <random>
네임스페이스: std