Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/numeric/random/discrete distribution/probabilities"

From cppreference.com
m (stray })
m (headers sorted, fmt)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{cpp/numeric/random/discrete_distribution/title | probabilities}}
 
{{cpp/numeric/random/discrete_distribution/title | probabilities}}
{{cpp/numeric/random/discrete_distribution/sidebar}}
+
{{cpp/numeric/random/discrete_distribution/}}
{{ddcl list begin}}
+
{{begin}}
{{ddcl list item | notes={{mark since c++11}} |1=
+
{{|=c++11|1=
 
std::vector<double> probabilities() const;
 
std::vector<double> probabilities() const;
 
}}
 
}}
{{ddcl list end}}
+
{{end}}
  
Obtains a {{cpp|std::vector<double>}} containing the individual probabilities of each integer that is generated by this distribution.
+
Obtains a {{|std::vector<double>}} containing the individual probabilities of each integer that is generated by this distribution.
  
 
===Parameters===
 
===Parameters===
Line 13: Line 13:
  
 
===Return value===
 
===Return value===
An object of type {{cpp|std::vector<double>}}
+
An object of type {{|std::vector<double>}}
  
 
===Example===
 
===Example===
{{example cpp
+
{{example
| code=
+
|code=
 
#include <iostream>
 
#include <iostream>
#include <vector>
 
 
#include <random>
 
#include <random>
 +
 +
 
int main()
 
int main()
 
{
 
{
 
     std::discrete_distribution<> d({40, 10, 10, 40});
 
     std::discrete_distribution<> d({40, 10, 10, 40});
 
     std::vector<double> p = d.probabilities();
 
     std::vector<double> p = d.probabilities();
     for(auto n : p)
+
     for (auto n : p)
 
         std::cout << n << ' ';
 
         std::cout << n << ' ';
 
     std::cout << '\n';
 
     std::cout << '\n';
 
}
 
}
| output=
+
|output=
 
0.4 0.1 0.1 0.4
 
0.4 0.1 0.1 0.4
 
}}
 
}}
 +
 +

Latest revision as of 07:44, 30 April 2023

 
 
 
 
 
std::vector<double> probabilities() const;
(since C++11)

Obtains a std::vector<double> containing the individual probabilities of each integer that is generated by this distribution.

[edit] Parameters

(none)

[edit] Return value

An object of type std::vector<double>.

[edit] Example

#include <iostream>
#include <random>
#include <vector>
 
int main()
{
    std::discrete_distribution<> d({40, 10, 10, 40});
    std::vector<double> p = d.probabilities();
    for (auto n : p)
        std::cout << n << ' ';
    std::cout << '\n';
}

Output:

0.4 0.1 0.1 0.4