Created
October 1, 2013 15:58
-
-
Save summerlight/6780771 to your computer and use it in GitHub Desktop.
random number generation with discrete probability in C++11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <random> | |
| #include <map> | |
| #include <iostream> | |
| int main() | |
| { | |
| using namespace std; | |
| mt19937 engine; | |
| discrete_distribution<> dist = {10, 20, 30, 40}; | |
| map<int, int> result; | |
| for (auto i = 0; i < 100000; i++) { | |
| result[dist(engine)]++; | |
| } | |
| for (auto&& count : result) { | |
| cout << count.second << endl; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment