std::discre...robabilities(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 NAME 🌸

std::discrete_distribution::probabilities β€” bestie, it's literally the member function that hands you back the probabilities πŸ’… (and yes, the manual name is C++ Standard Libary up top, typo and all, we don't gatekeep, we don't fix, we just vibe 🫢 β€” this page lives in section 3, the C++ Standard Library section)

✨ SYNOPSIS ✨

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

Okay so what even is this? It obtains a std::vector<double> containing the individual probabilities of each integer that is generated by this distribution. That's the whole thing. She's an icon, she's simple, she ate πŸ”₯

Note the (since C++11) β€” she's been here since C++11, a founding mother πŸ‘‘

πŸŽ€ PARAMETERS πŸŽ€

  • (none) β€” not a single parameter, not one, zero, nada, she takes no arguments and needs no arguments, main character energy fr fr 😌

πŸ’– RETURN VALUE πŸ’–

An object of type std::vector<double>. That's it. That's the return value. A whole vector of doubles, just for you, no cap 🌈

πŸ¦‹ EXAMPLE πŸ¦‹

The manpage literally says "Run this code" and honestly? Run it. Go off ✨

#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

See how that works?? You fed in {40, 10, 10, 40} and it normalized them into 0.4 0.1 0.1 0.4 β€” the individual probabilities, exactly what the tin says, we love a function that does what it says πŸ’€βœ¨


Heads up bestie: only the things listed above appear on this page β€” no extra secret options, no hidden overloads, no surprise environment variables. What you see is what you get, iykyk πŸ™ˆ

And that's the whole page! 🧚 Author credits aren't listed here, and the copyright/license lines aren't on this page either β€” but the source and version do carry a little signature: it's from http://cppreference.com, dated 2024.06.10, and the footer still calls it std::discre...robabilities(3). Slay, periodt πŸ’…πŸŽ€

πŸ“¦ where this page comes from