[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/numeric/random/geometric_distribution [Back]  [Original]

std::geometric_distribution cppreference.com
cppreference.com

std::geometric_distribution

cppreference.com

<metanoindex/>

 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
(C++17)
(C++20)
(C++11)
(C++11)
(C++17)
(C++17)
(C++20)
(C++20)
(C++11)
(C++17)
(C++20)
(C++23)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
 
 
 
<tbody> </tbody>
template< class IntType = int > class geometric_distribution;
( C++11)
i ,
:
Produces random non-negative integer values i, distributed according to discrete probability function:
Google.
. .
P(i|p) = p (1 p)i
/ ( p), .
:
The value represents the number of yes/no trials (each succeeding with probability p) which are necessary to obtain a single success.
Google.
. .
std::geometric_distribution<>(p) std::negative_binomial_distribution<>(1, p). std::exponential_distribution.
:
std::geometric_distribution<>(p) is exactly equivalent to std::negative_binomial_distribution<>(1, p). It is also the discrete counterpart of std::exponential_distribution.
Google.
. .

-

result_type IntType
param_type
,
:
the type of the parameter set, unspecified
Google.
. .

-

:
constructs new distribution
Google.
. .

(public -) []
:
resets the internal state of the distribution
Google.
. .

(public -) []
:
Generation
Google.
. .

(public -) []
:
Characteristics
Google.
. .
( true )
:
returns the p distribution parameter (probability of a trial generating true)
Google.
. .

(public -) []
:
gets or sets the distribution parameter object
Google.
. .

(public -) []
:
returns the minimum potentially generated value
Google.
. .

(public -) []
:
returns the maximum potentially generated value
Google.
. .

(public -) []

,

(C++11)(C++11)( C++20)

() []

/
() []

geometric_distribution <> (0,5) , ,
:
geometric_distribution<>(0.5) is the default and represents the number of coin tosses that are required to get heads
Google.
. .

#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <random>
int main()
{
    std::random_device rd;
    std::mt19937 gen(rd());

    std::geometric_distribution<> d; // same as std::negative_binomial_distribution<> d(1, 0.5);

    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. "Geometric Distribution." MathWorld - Wolfram Web.
:
Weisstein, Eric W. "Geometric Distribution." From MathWorld--A Wolfram Web Resource.
Google.
. .

Web Proxy Viewer  |  New URL  |  Original Page