Difference between revisions of "cpp/numeric/random/discrete distribution/probabilities"
From cppreference.com
< cpp | numeric | random | discrete distribution
m (langlinks) |
Andreas Krug (Talk | contribs) m (headers sorted, fmt) |
||
Line 2: | Line 2: | ||
{{cpp/numeric/random/discrete_distribution/navbar}} | {{cpp/numeric/random/discrete_distribution/navbar}} | ||
{{dcl begin}} | {{dcl begin}} | ||
− | {{dcl | since=c++11 |1= | + | {{dcl|since=c++11|1= |
std::vector<double> probabilities() const; | std::vector<double> probabilities() const; | ||
}} | }} | ||
Line 13: | Line 13: | ||
===Return value=== | ===Return value=== | ||
− | An object of type {{c|std::vector<double>}} | + | An object of type {{c|std::vector<double>}} |
===Example=== | ===Example=== | ||
{{example | {{example | ||
− | + | |code= | |
#include <iostream> | #include <iostream> | ||
− | |||
#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= | |
0.4 0.1 0.1 0.4 | 0.4 0.1 0.1 0.4 | ||
}} | }} | ||
{{langlinks|cs|de|es|fr|it|ja|ko|pl|pt|ru|zh}} | {{langlinks|cs|de|es|fr|it|ja|ko|pl|pt|ru|zh}} |
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
Run this code
#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